Hello So I have a pandas df with urls I then download/load cache then store that into the df. The problem arises because pandas stores the numpy arrays as ndarrays so their shape is lost. Is there any way to tell tensorflow the shape of the stored arrays?
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: Failed to convert a NumPy array to a Tensor (Unsupported object type 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