在Keras中使用深度卷积层神经网络训练模型时,出现以下错误。在我的数据处理层之一中,出现以下错误。
Traceback (most recent call last):
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/samuel/Documents/All-In-One/train/__main__.py", line 24, in <module>
main()
File "/home/samuel/Documents/All-In-One/train/__main__.py", line 20, in main
net.train()
File "nets/__init__.py", line 337, in train
self.train_pose_network()
File "nets/__init__.py", line 293, in train_pose_network
callbacks = callbacks
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/site-packages/keras/engine/training.py", line 2160, in fit_generator
val_x, val_y, val_sample_weight)
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/site-packages/keras/engine/training.py", line 1480, in _standardize_user_data
exception_prefix='target')
File "/home/samuel/anaconda2/envs/newenv/lib/python2.7/site-packages/keras/engine/training.py", line 123, in _standardize_input_data
str(data_shape))
ValueError: Error when checking target: expected pose to have shape (3,) but got array with shape (2,)
在nets / init .py中有以下代码。
def train_pose_network(self):
pose_model = self.model.get_model_with_labels(["pose"])
dataset = self.getDatasetFromString(self.config)
if not dataset.dataset_loaded:
dataset.load_dataset()
X_test = dataset.test_dataset_images
X_test = X_test.reshape(-1,self.config.image_shape[0],self.config.image_shape[1],self.config.image_shape[2])
pose_test = dataset.test_dataset["is_face"].as_matrix().astype(np.uint8)
pose_test = np.eye(2)[pose_test]
pose_model.compile(loss = keras.losses.binary_crossentropy,optimizer=keras.optimizers.Adamax(self.config.getLearningRate(),beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0),metrics=["accuracy"])
callbacks = None
pose_model.summary()
pose_model.fit_generator(dataset.detection_data_genenerator(self.config.batch_size),
epochs = self.config.epochs,
steps_per_epoch = self.config.steps_per_epoch,
validation_data = [X_test,pose_test],
callbacks = callbacks
)
score = pose_model.evaluate(X_test,pose_test)
self.save_model(pose_model,score)
在表示callbacks = callbacks的行中,它正在检查期望的数组形状为(3,),但正在获取形状为(2,)的数组。我该如何避免这个问题?