为我提供了一个基本代码,我需要对其进行更改,以便能够将训练数据用作输入,而不是代码中的单个图像。由于xtrain.shape
会产生(50,000, 32, 32, 3)
格式,因此不确定是否要采用正确的方法。当我尝试将xtrain的每个值运行到调整器中,然后使用该数据作为预测值时,我得到resized_xtrain.shape
,它产生一个(224, 224, 3)
,而len(results)
产生50,000
resize_xtrain应该不是(50,000,224,224,3)吗?
任何有用的提示都将非常有用。我需要将数据设置到数组中,以便稍后用作randomForest分类器的输入。
这是给的:
from keras.applications.vgg19 import VGG19
from keras.preprocessing import image
from keras.applications.vgg19 import preprocess_input
from keras.models import Model
import numpy as np
base_model = VGG19(weights='imagenet')
base_model.summary()
model = Model(inputs=base_model.input, outputs=base_model.get_layer('fc2').output)
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
fc2_features = model.predict(x)
fc2_features.shape
这就是我创建的:
from skimage import transform
from keras.models import Model
model2 = Model(inputs=base_model.input, outputs=base_model.get_layer('fc2').output)
results=[]
for i in range (50000):
resized_xtrain= transform.resize(x_train[i], (224, 224, 3), order=1, mode='reflect')
#img_path = 'elephant.jpg'
#img = image.load_img(img_path, target_size=(224, 224))
#x = image.img_to_array(img)
x = np.expand_dims(resized_xtrain, axis=0)
x = preprocess_input(x)
fc2_features = model2.predict(x)
fc2_features.shape
results.append(fc2_features)