如何解决TensorFlow - TFRecords 加载和转换带有边界框的图像
我正在尝试使用 TensorFlow 构建“汽车分类器”。
我有 1000 张带标签的 JPG 图像,800x800,带有边界框和相关的 annotations.coco.json;分成训练/验证/测试文件夹。
我已经使用下面的代码成功加载了 TFRecordDataset:
TFRecord 数据集加载步骤
# Load TfRecord data sets
raw_train = tf.data.TFRecordDataset([training_file])
raw_validation = tf.data.TFRecordDataset([validation_file])
raw_test = tf.data.TFRecordDataset([testing_file])
# Load label map
category_index = label_map_util.create_category_index_from_labelmap(label_map_file,use_display_name=True)
------------------------------------------------------------------------------------------
def extract_features(tfrecord):
# Extract features using the keys set during creation
features = {
'image/object/bbox/xmin': tf.io.VarLenFeature(dtype=tf.float32),'image/object/bbox/ymin': tf.io.VarLenFeature(dtype=tf.float32),'image/object/bbox/xmax': tf.io.VarLenFeature(dtype=tf.float32),'image/object/bbox/ymax': tf.io.VarLenFeature(dtype=tf.float32),'image/object/class/label': tf.io.VarLenFeature(dtype=tf.int64),'image/width': tf.io.FixedLenFeature([],tf.int64),'image/height': tf.io.FixedLenFeature([],'image/encoded': tf.io.FixedLenFeature([],tf.string)
}
# Extract the data record
sample = tf.io.parse_single_example(tfrecord,features)
image = tf.io.decode_image(sample['image/encoded'])
label = sample['image/object/class/label']
return [image,label]
raw_train = raw_train.map(extract_features)
raw_validation = raw_validation.map(extract_features)
raw_test = raw_test.map(extract_features)
为训练转换/调整图像大小
ORIGINAL_IMG_SIZE = 800
RESIZE_IMG_SIZE = 160 # All images will be resized to 160x160 or 614x614 maybe for Yolo?
def format_example(image,label):
#https://stackoverflow.com/questions/62957726/i-got-value-error-that-image-has-no-shape-while-converting-image-to-tensor-for-p
image.set_shape([ORIGINAL_IMG_SIZE,ORIGINAL_IMG_SIZE,3])
image = tf.cast(image,tf.float32)
image = (image/127.5) - 1
image = tf.image.resize(image,(RESIZE_IMG_SIZE,RESIZE_IMG_SIZE))
return image,label
-
Tensorflow 示例似乎只讨论调整整个图像的大小,而没有讨论如何调整图像中的边界框和边界框标签的大小。
-
有没有人有任何示例说明如何调整图像大小以及图像中包含的边界框?
训练管道
-
再次强调,Tensorflow 示例似乎只使用整个图像进行训练,而不是使用带有边界框和相关边界框标签的图像进行训练。
-
有没有人有任何使用带有边界框和相关边界框标签的图像进行 TensorFlow 迁移学习训练的示例?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。