作为标题状态,只有一个image+label从我的my记录文件中加载。每个tfrecord中都有可变数量的图像/标签,但始终至少有8对。我使用TF版本: 2.4.1
可能与此有关,我收到了这样的警告:
警告:tensorflow:签名无法在0x7fbb7db99160>转换export AUTOGRAPH_VERBOSITY=10上)并附加完整的输出。原因:模块'gast‘没有属性'Index’来沉默此警告,用@tf.autograph.experimental.do_not_convert装饰函数
下面是我用来加载测试数据的函数。任何帮助都是非常感谢的。
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发布于 2022-03-30 18:12:51
事实证明,这个问题是愚蠢的,与我在问题中发布的功能无关。问题是,对于输入到模型中的steps_per_epoch,我有以下值。
steps_per_epoch = len(training_filenames) // BATCH_SIZE由于文件包含多个案例,len(training_filenames)需要乘以每个文件中的案例数。
steps_per_epoch = len(training_filenames) * images_in_file // BATCH_SIZEhttps://stackoverflow.com/questions/71654046
复制相似问题