通过tf.data.dataset.from_generator迭代时出错

发布于 2025-02-09 11:44:52 字数 1680 浏览 3 评论 0原文

我想通过使用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:

Data Adapter Code and the error

More description of the error:

Error Description

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文