【发布时间】:2021-01-05 12:02:33
【问题描述】:
我使用 TFF,我的数据集有一个 binary_mode 类,这就是我声明输入的方式:
genv0 = img_genv.flow_from_directory(pathv0,(224, 224),'rgb', batch_size=2, class_mode='binary')
train_data = tf.data.Dataset.from_generator(genv0, output_types=(tf.float32, tf.float32), output_shapes = ([2,224,224,3],[2,1])
这是我的 sample_batch :
images, labels = next(img_gen.flow_from_directory(path0,target_size=(224, 224), batch_size=2, class_mode='binary'))
我在我的模型中添加了这一层
model_output = tf.keras.layers.Dense(1, activation="sigmoid")(last_layer)
model.compile(optimizer=tf.keras.optimizers.SGD(lr=0.001)
loss=tf.keras.losses.BinaryCrossentropy(),
metrics=([tf.keras.metrics.BinaryAccuracy()))
运行我的代码时,我发现这个错误:
ValueError: Shapes (None, 1) and (None,) are incompatible
我认为问题在于 sample_batch 没有采用 bainary 模式的标签。 我该如何解决这个问题 谢谢
【问题讨论】:
-
你能打印出样品批次中
images和labels的形状吗?
标签: tensorflow tensorflow2.0 tensorflow-federated