我正在重新创建 DnCNN,即高斯降噪器,它使用一系列卷积层进行图像到图像的预测。它训练得非常好,但是当我尝试执行列表(model.predict(..))时,出现错误:
标签不能为 none
我实际上将我的 EstimatorSpec 的所有规范参数明确地放在那里,因为它们是根据调用 Estimator 的方法(train/eval/predict)懒惰地评估的。
def DnCNN_model_fn (features, labels, mode):
# some convolutinons here
return tf.estimator.EstimatorSpec(
mode=mode,
predictions=conv_last + input_layer,
loss=tf.losses.mean_squared_error(
labels=labels,
predictions=conv_last + input_layer),
train_op=tf.train.AdamOptimizer(learning_rate=0.001, epsilon=1e-08).minimize(
loss=tf.losses.mean_squared_error(
labels=labels,
predictions=conv_last + input_layer),
global_step=tf.train.get_global_step()),
eval_metric_ops={
"accuracy": tf.metrics.mean_absolute_error(
labels=labels,
predictions=conv_last + input_layer)}
)
Run Code Online (Sandbox Code Playgroud)
将其放入估计器中:
d = datetime.datetime.now()
DnCNN = tf.estimator.Estimator(
model_fn=DnCNN_model_fn,
model_dir=root + 'model/' +
"DnCNN_{}_{}_{}_{}".format(d.month, d.day, d.hour, d.minute),
config=tf.estimator.RunConfig(save_summary_steps=2,
log_step_count_steps=10)
)
Run Code Online (Sandbox Code Playgroud)
训练模型后,我进行如下预测:
test_input_fn = tf.estimator.inputs.numpy_input_fn(
x= test_data[0:2,:,:,:],
y= None,
batch_size=1,
num_epochs=1,
shuffle=False)
predicted = DnCNN.predict(input_fn=test_input_fn)
list(predicted) # …Run Code Online (Sandbox Code Playgroud)