【发布时间】:2020-12-21 09:57:03
【问题描述】:
我将 keras 用于回归模型。我正在尝试微调 VGG16。一切正常。在我添加tensorflow.keras.applications.vgg16.preprocess_input 以根据 VGG16 对图像进行预处理后,出现以下错误:
ValueError:数据基数不明确: x 尺寸:1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 尺码:422 确保所有数组都包含相同数量的样本。
加载图像后,我循环浏览主题并应用它:
from keras.preprocessing.image import img_to_array
images = []
for img in loaded_images:
img = img_to_array(img)
img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
img = preprocess_input(img)
images.append(img)
actual = actual.reshape(1,-1)
assert len(images) == len(actual)
之后,我将图像划分为训练集、有效集和测试集,如下所示:
编辑:
train_images,test_images, train_actual_score , test_actual_score = train_test_split(images, scaled_train_mos, test_size=0.20, random_state=42)
最后我调用了fit func:
history = model.fit(x=train_images, y=train_actual_score, validation_data=(test_images, test_actual_score), epochs=30, batch_size=8, verbose=2)
更新:
这里是standalone code 来重现上述问题。
【问题讨论】:
-
你能添加一个独立的代码来重现这个问题吗?为您的图像使用生成的数据。
-
@AniketBote,你到底是什么意思?代码的哪一部分?
-
我可以在我的系统上运行的代码,而无需下载任何会重现您的错误的数据。
-
@AniketBote 我创建了一个colab,这里是链接colab.research.google.com/drive/…
标签: python numpy tensorflow keras regression