python - InvalidArgumentError:reshape 的输入是一个具有 320 个值的张量,但请求的形状需要 5760 的倍数
问题描述
该项目是为了判断一张人脸图像是否是假的,这就是我使用二进制分类的原因。我正在尝试使用验证数据(虽然我不太确定它做了什么)来训练和测试我的模型,因为将训练和测试数据传递到模型中会导致模型仅输出 2 个准确度。我收到一个错误,说输入形状需要是 5760 的倍数,而我的是 320。
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
training_set =
train_datagen.flow_from_directory("/content/drive/MyDrive/real_and_fake_face/output/train",
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')
test_datagen = ImageDataGenerator(rescale = 1./255)
test_set =
test_datagen.flow_from_directory('/content/drive/MyDrive/real_and_fake_face/output/test',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')
val_datagen = ImageDataGenerator(rescale = 1./255)
val_set =
val_datagen.flow_from_directory('/content/drive/MyDrive/real_and_fake_face/output/val',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')```
Images are 600x600x3. Image count is about 1000 and is split into train, test, and validation class. Images are stored in Google Drive and imported using a module.
Full error message:
``` InvalidArgumentError Traceback (most recent call last)
<ipython-input-10-2180c8efba4c> in <module>()
----> 1 model.fit(training_set, steps_per_epoch= 50, epochs=20, validation_data= val_set,
validation_steps= 50)
6 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in
quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
InvalidArgumentError: Input to reshape is a tensor with 320 values, but the requested shape
requires a multiple of 5760
[[node sequential/flatten/Reshape (defined at <ipython-input-10-2180c8efba4c>:1) ]]
[Op:__inference_train_function_11377]
Function call stack:
train_function```
解决方案
推荐阅读
- unity3d - Unity - 触摸屏幕时显示精灵
- java - 如何在二维数组中找到同时在行中较高且在列中较低的数字的索引
- node.js - 我总是对 mern 项目(nodejs 和 reactjs)使用“并发”,但现在我无法同时安装
- python - 警告消息说找不到“.credentials”文件夹,Safari 不会加载“localhost”
- decision-tree - Rapidminer 决策树结果
- haskell - 如何在 Haskell Chart 包中设置图表的背景颜色?
- c++ - 如何在代码块控制台中打印西里尔文文本
- java - java.lang.NoClassDefFoundError: com/google/appengine/api/urlfetch/HTTPMethod
- django - Django搜索中的部分匹配
- python - 在 Visual Studio 2017 中使用 Pybind11 for Python 构建 CPP 时出现编译错误