Python TensorFlow-TFR使用边界框加载和变换图像

Python TensorFlow-TFR使用边界框加载和变换图像,python,tensorflow,tensorflow-datasets,transfer-learning,Python,Tensorflow,Tensorflow Datasets,Transfer Learning,我正在尝试使用TensorFlow构建一个“汽车分类器” 我有1000个带标签的JPG图像,800x800,带有边界框和相关注释。coco.json;分为训练/验证/测试文件夹 我已使用以下代码成功加载TFRecordDataset的: TFRecord数据集加载步骤 # Load TfRecord data sets raw_train = tf.data.TFRecordDataset([training_file]) raw_validation = tf.data.TFRecordDat

我正在尝试使用TensorFlow构建一个“汽车分类器”

我有1000个带标签的JPG图像,800x800,带有边界框和相关注释。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([], tf.int64),
        '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迁移学习培训的示例,其中包括带有边框和相关边框标签的图像?