首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >只从TFrecords中提取单个图像。

只从TFrecords中提取单个图像。
EN

Stack Overflow用户
提问于 2022-03-28 21:42:06
回答 1查看 39关注 0票数 0

作为标题状态,只有一个image+label从我的my记录文件中加载。每个tfrecord中都有可变数量的图像/标签,但始终至少有8对。我使用TF版本: 2.4.1

可能与此有关,我收到了这样的警告:

警告:tensorflow:签名无法在0x7fbb7db99160>转换export AUTOGRAPH_VERBOSITY=10上)并附加完整的输出。原因:模块'gast‘没有属性'Index’来沉默此警告,用@tf.autograph.experimental.do_not_convert装饰函数

下面是我用来加载测试数据的函数。任何帮助都是非常感谢的。

代码语言:javascript
复制
def parse_tfr_element(element):

    data = {
      'height': tf.io.FixedLenFeature([], tf.int64),
      'width':tf.io.FixedLenFeature([], tf.int64),
      'depth':tf.io.FixedLenFeature([], tf.int64),
      'raw_label':tf.io.FixedLenFeature([], tf.string),#tf.string = bytestring (not text string)
      'raw_image' : tf.io.FixedLenFeature([], tf.string),#tf.string = bytestring (not text string)
    }


    content = tf.io.parse_single_example(element, data)

    height = content['height']
    width = content['width']
    depth = content['depth']
    raw_label = content['raw_label']
    raw_image = content['raw_image']


    #get our 'feature'-- our image -- and reshape it appropriately
    feature = tf.io.parse_tensor(raw_image, out_type=tf.float16)
    feature = tf.reshape(feature, shape=[height,width,depth])
    label = tf.io.parse_tensor(raw_label, out_type=tf.int8)
    label = tf.reshape(label, shape=[height,width])
    return (feature, label)

def get_batched_dataset(filenames):
    option_no_order = tf.data.Options()
    option_no_order.experimental_deterministic = False

    dataset = tf.data.TFRecordDataset(filenames)
    dataset = dataset.with_options(option_no_order)
    dataset = dataset.map(parse_tfr_element, num_parallel_calls=AUTO)

    dataset = dataset.shuffle(2048)
    dataset = dataset.batch(BATCH_SIZE, drop_remainder=True) 


    return dataset
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-30 18:12:51

事实证明,这个问题是愚蠢的,与我在问题中发布的功能无关。问题是,对于输入到模型中的steps_per_epoch,我有以下值。

代码语言:javascript
复制
steps_per_epoch = len(training_filenames)  // BATCH_SIZE

由于文件包含多个案例,len(training_filenames)需要乘以每个文件中的案例数。

代码语言:javascript
复制
steps_per_epoch = len(training_filenames) * images_in_file  // BATCH_SIZE
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71654046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档