微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在tensorflow的dataset.map中调用的函数中未获取张量的值

如何解决在tensorflow的dataset.map中调用的函数中未获取张量的值

我正在尝试从map函数调用函数获取张量值。但是我遇到了这个错误

tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须使用dtype字符串输入占位符张量'args_0'的值 [[{{node args_0}}]]

我的代码如下

在我的主要功能中:

# created instance of Preprocess class
preprocess = Preprocessor(is_train,TOTAL_CLASSES,OUTPUT_SHAPE)

# all the tfrecords which is present in ./tfrecords folder we will gate
dataset = tf.data.Dataset.list_files("./tfrecords")

# we will comprises it into one
dataset = tf.data.TFRecordDataset(dataset)

# Here I am mapped __call__ method which is present in Preprocess class
dataset = dataset.map(preprocess,num_parallel_calls=tf.data.experimental.AUTOTUNE)

现在在预处理类调用方法中,我遇到了错误 这是我的预处理课。在通话功能中,我遇到了错误

class Preprocessor(object):
    def __init__(self,is_train,num_classes,output_shape=(416,416)):
        self.is_train = is_train
        self.num_classes = num_classes
        self.output_shape = output_shape

    def __call__(self,example):
        features = self.parse_tfexample(example)
        encoded = features['image/encoded']
        image = tf.io.decode_jpeg(encoded)
        image = tf.cast(image,tf.float32)

        sess = tf.Session()

        # at this line I am getting error
        print(sess.run(image))

如何解决此问题。如果我对print(sess.run(image))进行注释,则此行的所有代码都可以正常工作。但是我想要映射函数中的张量值。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。