通过tf.data.dataset.from_generator迭代时出错
我想通过使用Python中的产量功能来构建自定义图像生产剂。 train_df 是具有两个列( Input :)的数据框,它包含通往我低分辨率图像的路径, upputs 列包含通往高分辨率图像的路径。 train_df dataframe的样本是在这里。 将图像传递到批处理方式。
from numpy import asarray
def get_train_image(dataframe=train_df):
for i in range(len(dataframe)):
input_image = cv2.imread(dataframe.input[i],cv2.COLOR_BGR2RGB)
input_image=cv2.resize(input_image,(80,120))
input_image=asarray(input_image)
input_image=input_image[np.newaxis,...]
output_image = cv2.imread(dataframe.output[i],cv2.COLOR_BGR2RGB)
output_image=cv2.resize(output_image,(120,160))
output_image=asarray(output_image)
output_image=output_image[np.newaxis,...]
yield tf.convert_to_tensor(input_image),tf.convert_to_tensor(output_image)
作为图像生成器, 当我使用下一个功能测试时。 当我将数据适配器传递给CNN时,我会出错
tensorflow(tf.data.dataSet.from_generator()以批量级的方式传递CNN的图像, .dataset.from_generator(get_train_image,output_signature =(tf.tensorspec(shape =(1,120,80,3),dtype = tf.float32),tf.tensorspec,tf.tensorspec(shape =(1,160,120,3),dtype =(1,160,120,3) ,args = [train_df])
上面代码的图像:
错误的更多描述:
I want to build a custom ImageGenerator by using yield function in Python. train_df is the dataframe which have two columns (input: that contains path to my low resolution image and output columns contains path to high resolution image. A sample of train_df dataframe is here. I made an yield function as Image Generator to pass the images into batchwise manner. Code for ImageGenerator:
from numpy import asarray
def get_train_image(dataframe=train_df):
for i in range(len(dataframe)):
input_image = cv2.imread(dataframe.input[i],cv2.COLOR_BGR2RGB)
input_image=cv2.resize(input_image,(80,120))
input_image=asarray(input_image)
input_image=input_image[np.newaxis,...]
output_image = cv2.imread(dataframe.output[i],cv2.COLOR_BGR2RGB)
output_image=cv2.resize(output_image,(120,160))
output_image=asarray(output_image)
output_image=output_image[np.newaxis,...]
yield tf.convert_to_tensor(input_image),tf.convert_to_tensor(output_image)
Image of above code Image_of_above_code. When I test this by using next function.It works fine Extracting_data_from_generator. I used DataAdapter provided by tensorflow (tf.data.Dataset.from_generator()) to pass the image in the CNN in batchwise manner and I got error while iterating. Same error is coming when I pass the Data Adaptor to CNN.
train_data=tf.data.Dataset.from_generator( get_train_image,output_signature=(tf.TensorSpec(shape=(1,120,80,3),dtype=tf.float32), tf.TensorSpec(shape=(1,160,120,3),dtype=tf.float32) ), args=[train_df])
Image of code above:
More description of the error:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论