【发布时间】:2021-03-30 16:29:17
【问题描述】:
你好所以我有一个带有url的pandas df,然后我下载/加载缓存,然后将其存储到df中。出现问题是因为 pandas 将 numpy 数组存储为 ndarrays,因此它们的形状丢失了。 有没有办法告诉 tensorflow 存储数组的形状?
def NN(self):
#Trains on validation then commence batch prediction
data = self.category_validation.agg({'URL':self.process_image,'label':self.le.fit_transform}).dropna()
print(data['URL'].values[0])
print(data['URL'].values[0].shape)
print(data['URL'].values.shape)
exit(1)
#One of Keras' best templates
self.nn = model(...)
#Compile the model
self.nn.compile(...)
#Fit the first instance of the data
self.nn.fit(data['URL'].values,data['label'].values)
tf.Tensor(..., shape=(299, 299, 3), dtype=float32) (299, 299, 3) (490,)
ValueError:无法将 NumPy 数组转换为张量(不支持的对象类型 tensorflow.python.framework.ops.EagerTensor)。
def process_image(self,url):
#Read image from filepath and reshape it to the appropriate shape for model
path = "path/"+self.clean_url(url)
#Checks if files exists, if not it tries to download if that doesn't work
if os.path.exists(path):
image = tf.keras.preprocessing.image.load_img(path,target_size=(299,299))
image = tf.keras.preprocessing.image.img_to_array(image)
elif self.get_image(url) == 0:
return float('nan')
else:
image = tf.keras.preprocessing.image.load_img(path,target_size=(299,299))
image = tf.keras.preprocessing.image.img_to_array(image)
return image/255
【问题讨论】:
标签: python pandas numpy tensorflow