【发布时间】:2022-01-24 07:48:51
【问题描述】:
我们的模型看起来像:
model_name = 'model_inceptionResNetV2_aug'
def get_model_inceptionResNetV2(input_shape):
model = InceptionResNetV2(weights='imagenet', include_top=False,
input_shape=input_shape, pooling='avg')
perut_input = Input(input_shape)
bokong_input = Input(input_shape)
encoded_perut = model(perut_input)
encoded_bokong = model(bokong_input)
# Flattening the output for the dense layer
fout2 = Flatten()(encoded_perut)
fout3 = Flatten()(encoded_bokong)
# Getting the dense output
dense = Dense(2)
dout2 = dense(fout2)
dout3 = dense(fout3)
# Concatenating the final output
out = Concatenate(axis=-1)([dout2, dout3])
# output berat
dense_out = Dense(12, activation='softmax') #jumlah kelas
final_out = dense_out(out)
# output
model_densenet = Model(inputs=[perut_input, bokong_input],outputs=final_out)
return model_densenet
我收到错误消息:
1/11 [==============================] - ETA: 0s - loss: 3.1334 - accuracy: 0.2159/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:78: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-25-9d2c5fd65355> in <module>()
1 model.fit(train_batch, epochs = epochs,
2 verbose = 1, callbacks = [stop_train_callback, model_checkpoint_callback, history],
----> 3 validation_data = valid_batch)
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
104 dtype = dtypes.as_dtype(dtype).as_datatype_enum
105 ctx.ensure_initialized()
--> 106 return ops.EagerTensor(value, ctx.device_name, dtype)
107
108
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).
我尝试将 dtype 转换为最适合的类型:string 和 float32(用于数字和目标类)。目标类 dtype 是否应该转换为“对象”?也试过了,还是不行,
请提供任何线索。
【问题讨论】:
-
请列出您的代码的导入,以及您是如何调用代码的。查看如何创建minimal reproducible example
-
问题很可能出在数据上,而不是模型上。真的一致吗?批次的所有元素的形状相同?这种问题已经有很多SO了。
标签: python numpy conv-neural-network