我试图建立一个用于图像分割的Unet卷积神经网络,但是当我尝试使用输入数据编译该模型时,出现了形状不兼容的错误消息。
int main()
{
int num1, num2, i, GCD;
printf("Please enter a positive integer: \n");
scanf("%d" ,&num1);
printf("Please enter a positive integer:\n");
scanf("%d", &num2);
if (num1 >0 && num2 > 0) {
for(i = 1; i <= num1 && i <= num2; i++)
{
if(num1 % i == 0 && num2 % i == 0)
GCD = i;
}
}
else {
printf("I'm sorry that number is unrecognized or negative.\n");
}
printf("The largest integer that divides both %d and %d is: %d\n",num1,num2, GCD);
return 0;
}
当我已经检查了所有输入形状是否匹配时,问题出在什么地方?被忽略的是什么以及如何解决?
我已经尝试过
print(x_data.shape)
print(x_test.shape)
print(y_data.shape)
print(y_test.shape)
>>
(4, 767, 1022, 3)
(4, 767, 1022, 3)
(4, 767, 1022, 3)
(4, 767, 1022, 3)
>>>>
model = sm.Unet('resnet34', classes=1, activation='sigmoid')
model.compile(
'Adam',
loss=sm.losses.bce_jaccard_loss,
metrics=[sm.metrics.iou_score],
)
>>>>
model.fit(
x=x_data,
y=y_data,
batch_size=16,
epochs=100,
validation_data=(x_test, y_test),
)
>>
Epoch 1/100
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-27-6cf659e4ef4f> in <module>()
4 batch_size=16,
5 epochs=100,
----> 6 validation_data=(x_test, y_test),
7 )
10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
971 except Exception as e: # pylint:disable=broad-except
972 if hasattr(e, "ag_error_metadata"):
--> 973 raise e.ag_error_metadata.to_exception(e)
974 else:
975 raise
ValueError: in user code:
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:806 train_function *
return step_function(self, iterator)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:796 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:1211 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2585 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2945 _call_for_each_replica
return fn(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:789 run_step **
outputs = model.train_step(data)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:747 train_step
y_pred = self(x, training=True)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py:985 __call__
outputs = call_fn(inputs, *args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/functional.py:386 call
inputs, training=training, mask=mask)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/functional.py:508 _run_internal_graph
outputs = node.layer(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py:985 __call__
outputs = call_fn(inputs, *args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/merge.py:183 call
return self._merge_function(inputs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/merge.py:522 _merge_function
return K.concatenate(inputs, axis=self.axis)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/dispatch.py:201 wrapper
return target(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py:2881 concatenate
return array_ops.concat([to_dense(x) for x in tensors], axis)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/dispatch.py:201 wrapper
return target(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py:1654 concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py:1222 concat_v2
"ConcatV2", values=values, axis=axis, name=name)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:744 _apply_op_helper
attrs=attr_protos, op_def=op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py:593 _create_op_internal
compute_device)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:3485 _create_op_internal
op_def=op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1975 __init__
control_input_ops, op_def)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1815 _create_c_op
raise ValueError(str(e))
ValueError: Dimension 2 in both shapes must be equal, but are 512 and 511. Shapes are [?,384,512] and [?,384,511]. for '{{node functional_3/decoder_stage3_concat/concat}} = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32](functional_3/decoder_stage3_upsampling/resize/ResizeNearestNeighbor, functional_3/relu0/Relu, functional_3/decoder_stage3_concat/concat/axis)' with input shapes: [?,384,512,64], [?,384,511,64], [] and with computed input tensors: input[2] = <3>.
如此处https://github.com/titu1994/Image-Super-Resolution/issues/27所示,但问题仍然存在。
使用Google Colab。
答案 0 :(得分:2)
聚会有点晚了,但是您的问题来自输入宽度和高度不能被 32 整除的事实;确保您对 UNet 使用可被 32 整除的值,您的问题将得到解决。
您无需更改 Colab 环境或将频道顺序设置为 <ul>
<li>School</li>
<li>University</li>
<li>Kindergarden</li>
</ul>
。