1

深層学習フレームワーク Caffe で関数 y = x^2 を学習するようにニューラル ネットワークをトレーニングしようとしていました。これが私のコードです:

データ生成コード:

import numpy as np
import lmdb
import caffe

Ntrain = 100
Ntest = 20
K = 1
H = 1
W = 1

Xtrain = np.uint8(np.random.randint(0, 256, size=(Ntrain,K,H,W)))
Xtest = np.uint8(np.random.randint(0, 256, size=(Ntest,K,H,W)))
ytrain = np.zeros(Ntrain, dtype=np.int32)
ytest = np.zeros(Ntest, dtype=np.int32)

for i in range(Xtrain.shape[0]):
    ytrain[i] = int(Xtrain[i,0,0,0]) * int(Xtrain[i,0,0,0])

for i in range(Xtest.shape[0]):
    ytest[i] = int(Xtest[i,0,0,0]) * int(Xtest[i,0,0,0])

env = lmdb.open('expt/expt_train')

for i in range(Ntrain):
    datum = caffe.proto.caffe_pb2.Datum()
    datum.channels = Xtrain.shape[1]
    datum.height = Xtrain.shape[2]
    datum.width = Xtrain.shape[3]
    datum.data = Xtrain[i].tobytes()
    datum.label = int(ytrain[i])
    str_id = '{:08}'.format(i)

    with env.begin(write=True) as txn:
        txn.put(str_id.encode('ascii'), datum.SerializeToString())


env = lmdb.open('expt/expt_test')

for i in range(Ntest):
    datum = caffe.proto.caffe_pb2.Datum()
    datum.channels = Xtest.shape[1]
    datum.height = Xtest.shape[2]
    datum.width = Xtest.shape[3]
    datum.data = Xtest[i].tobytes()
    datum.label = int(ytest[i])
    str_id = '{:08}'.format(i)

    with env.begin(write=True) as txn:
        txn.put(str_id.encode('ascii'), datum.SerializeToString())

ソルバー ファイル:

net: "expt/expt.prototxt"

max_iter: 500
test_iter: 20
test_interval: 100
display: 100

base_lr: 0.001
momentum: 0.9

lr_policy: "inv"

snapshot_prefix: "expt/expt"
snapshot_diff: true

solver_mode: CPU
solver_type: SGD

debug_info: true

カフェ モデル:

name: "expt"

layer {
    name: "Expt_Data_Train"
    type: "Data"
    top: "data"
    top: "label"    

    include {
        phase: TRAIN
    }

    data_param {
        source: "expt/expt_train"
        backend: LMDB
        batch_size: 1
    }
}


layer {
    name: "Expt_Data_Validate"
    type: "Data"
    top: "data"
    top: "label"    

    include {
        phase: TEST
    }

    data_param {
        source: "expt/expt_test"
        backend: LMDB
        batch_size: 1
    }
}


layer {
    name: "IP1"
    type: "InnerProduct"
    bottom: "data"
    top: "ip1"

    inner_product_param {
        num_output: 2
    }
}

layer {
    name: "IP2"
    type: "InnerProduct"
    bottom: "ip1"
    top: "ip2"

    inner_product_param {
        num_output: 1
    }
}

layer {
    name: "Loss"
    type: "EuclideanLoss"
    bottom: "ip2"
    bottom: "label"
    top: "loss"
}

信じられない 10^8 のオーダーのエラーが発生します。ネットは、単一の入力を取り、単一の出力を生成することになっています。入力は [0,255] の範囲の整数で、出力はそれぞれの入力の 2 乗であると想定されます。このような大きなエラーが発生する理由は何ですか?

4

0 に答える 0