我正在构建一个图像分类器,并尝试使用keras计算数据集的功能,但我的数组维度不是正确的格式。我越来越
ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape (324398, 1)
我的代码是这样的:
import glob
from keras.applications.resnet50 import ResNet50
def extract_resnet(X):
# X : images numpy array
resnet_model = ResNet50(input_shape=(image_h, image_w, 3),
weights='imagenet', include_top=False) # Since top layer is the fc layer used for predictions
features_array = resnet_model.predict(X)
return features_array
filelist = glob.glob('dataset/*.jpg')
myarray = np.array([np.array(Image.open(fname)) for fname in filelist])
print(extract_resnet(myarray))
所以看起来由于某种原因,当图像阵列应该是4维时,它只是二维的。如何转换myarray
以便它能够使用特征提取器?