これが私のネットワークです。ウェイトをロードしてから、ネットワークを微調整しました。アーキテクチャはずっと同じままでした。しかし、微調整 (block5 および fc レイヤーはトレーニング可能) 後にウェイトをロードすると、ウェイト値のウェイトの順序が変更されたため、ウェイトのロードが失敗します。
input_layer = Input(shape=(img_width,img_height,3),name = 'image_input')
model_vgg16_conv = VGG16(weights='imagenet',
include_top=False,input_shape=(200,200,3))
output_vgg16_conv = model_vgg16_conv(input_layer)
model_vgg16_conv.summary()
fl = Flatten(name='flatten')(output_vgg16_conv)
dense = Dense(512, activation='relu', name='fc1')(fl)
drop = Dropout(0.5, name='drop')(dense)
pred = Dense(nb_classes, activation='softmax', name='predictions')(drop)
fine_model = Model(outputs=pred,inputs=input_layer)
微調整前:
<HDF5 group "/image_input" (0 members)> []
<HDF5 group "/vgg16" (13 members)> [<HDF5 dataset "kernel:0": shape (3, 3, 3, 64), type "<f4">, <HDF5 dataset "bias:0": shape (64,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 64, 64), type "<f4">, <HDF5 dataset "bias:0": shape (64,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 64, 128), type "<f4">, <HDF5 dataset "bias:0": shape (128,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 128, 128), type "<f4">, <HDF5 dataset "bias:0": shape (128,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 128, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">]
<HDF5 group "/flatten" (0 members)> []
<HDF5 group "/fc1" (1 members)> [<HDF5 dataset "kernel:0": shape (18432, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">]
<HDF5 group "/drop" (0 members)> []
<HDF5 group "/predictions" (1 members)> [<HDF5 dataset "kernel:0": shape (512, 40), type "<f4">, <HDF5 dataset "bias:0": shape (40,), type "<f4">]
微調整後、重みが読み込まれないため、エラーが発生します。
<HDF5 group "/image_input" (0 members)> []
<HDF5 group "/vgg16" (13 members)> [<HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 3, 64), type "<f4">, <HDF5 dataset "bias:0": shape (64,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 64, 64), type "<f4">, <HDF5 dataset "bias:0": shape (64,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 64, 128), type "<f4">, <HDF5 dataset "bias:0": shape (128,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 128, 128), type "<f4">, <HDF5 dataset "bias:0": shape (128,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 128, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 256), type "<f4">, <HDF5 dataset "bias:0": shape (256,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 256, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">, <HDF5 dataset "kernel:0": shape (3, 3, 512, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">]
<HDF5 group "/flatten" (0 members)> []
<HDF5 group "/fc1" (1 members)> [<HDF5 dataset "kernel:0": shape (18432, 512), type "<f4">, <HDF5 dataset "bias:0": shape (512,), type "<f4">]
<HDF5 group "/drop" (0 members)> []
<HDF5 group "/predictions" (1 members)> [<HDF5 dataset "kernel:0": shape (512, 40), type "<f4">, <HDF5 dataset "bias:0": shape (40,), type "<f4">]
Traceback (most recent call last):
File "construct_index.py", line 87, in <module>
fine_model.load_weights(filepath)
File "/usr/local/lib/python2.7/site-packages/keras/engine/topology.py", line 2538, in load_weights
load_weights_from_hdf5_group(f, self.layers)
File "/usr/local/lib/python2.7/site-packages/keras/engine/topology.py", line 2970, in load_weights_from_hdf5_group
K.batch_set_value(weight_value_tuples)
File "/usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2153, in batch_set_value
get_session().run(assign_ops, feed_dict=feed_dict)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 961, in _run
% (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (3, 3, 512, 512) for Tensor u'Placeholder:0', which has shape '(3, 3, 3, 64)'
なぜか順番が変わった!
助けてください。このネットワークをトレーニングするのに何日もかかりました。これらの体重を減らす余裕はありません。ありがとう