下面的类没有地面实况例子

问题描述 投票:0回答:1

香港专业教育学院培训了来自动物园ssd_mobilenet_v1_coco模型对数据集〜25000交通标志图片这样一个48×48像素:dataset example

训练过程看起来罚款(从15.5〜开始下降至0.0135):training但是当我运行与测试数据集eval.py包含〜7K图片:eval start (warnings)并最终我看到的错误:下面的类没有地面实况例子[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67]

some more warnings

从该脚本生成CSV记录:

    from __future__ import division
from __future__ import print_function
from __future__ import absolute_import

import os
import io
import pandas as pd
import tensorflow as tf

import sys
sys.path.append("C:\\Users\\Jekoc\\Desktop\\TRAINING\\rus\\models-master\\research\\")
sys.path.append("C:\\Users\\Jekoc\\Desktop\\TRAINING\\rus\\models-master\\research\\object_detection\\utils")

from PIL import Image
from object_detection.utils import dataset_util
from collections import namedtuple, OrderedDict

flags = tf.app.flags
flags.DEFINE_string('csv_input', '', 'Path to the CSV input')
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
flags.DEFINE_string('image_dir', '', 'Path to images')
FLAGS = flags.FLAGS


# TO-DO replace this with label map
def class_text_to_int(row_label):
    if row_label != 0:
        return row_label
    else:
        None


def split(df, group):
    data = namedtuple('data', ['filename', 'object'])
    gb = df.groupby(group)
    return [data(filename, gb.get_group(x)) for filename, x in zip(gb.groups.keys(), gb.groups)]


def create_tf_example(group, path):
    with tf.gfile.GFile(os.path.join(path, '{}'.format(group.filename)), 'rb') as fid:
        encoded_png = fid.read()
    encoded_png_io = io.BytesIO(encoded_png)
    image = Image.open(encoded_png_io)
    width, height = image.size
    filename = group.filename.encode('utf8')
    image_format = b'png'#changed from jpg to png
    xmins = []
    xmaxs = []
    ymins = []
    ymaxs = []
    classes_text = []
    classes = []

    for index, row in group.object.iterrows():
        xmins.append(0 / width)
        xmaxs.append(48 /width) # size is 48x48px so xmaxs=1
        ymins.append(0 /height)
        ymaxs.append(48 /height) # size is 48x48px so ymaxs=1
        classes_text.append(str(row['class']).encode('utf8'))
        classes.append(class_text_to_int(row['class']))
    tf_example = tf.train.Example(features=tf.train.Features(feature={
        'image/height': dataset_util.int64_feature(height),
        'image/width': dataset_util.int64_feature(width),
        'image/filename': dataset_util.bytes_feature(filename),
        'image/source_id': dataset_util.bytes_feature(filename),
        'image/encoded': dataset_util.bytes_feature(encoded_png),
        'image/format': dataset_util.bytes_feature(image_format),
        'image/object/bbox/xmin': dataset_util.float_list_feature(xmins),
        'image/object/bbox/xmax': dataset_util.float_list_feature(xmaxs),
        'image/object/bbox/ymin': dataset_util.float_list_feature(ymins),
        'image/object/bbox/ymax': dataset_util.float_list_feature(ymaxs),
        'image/object/class/text': dataset_util.bytes_list_feature(classes_text),
        'image/object/class/label': dataset_util.int64_list_feature(classes),
    }))
    return tf_example


def main(_):
    writer = tf.python_io.TFRecordWriter(FLAGS.output_path)
    path = os.path.join(FLAGS.image_dir)
    examples = pd.read_csv(FLAGS.csv_input)
    grouped = split(examples, 'filename')
    for group in grouped:
        tf_example = create_tf_example(group, path)
        writer.write(tf_example.SerializeToString())

    writer.close()
    output_path = os.path.join(os.getcwd(), FLAGS.output_path)
    print('Successfully created the TFRecords: {}'.format(output_path))


if __name__ == '__main__':
    tf.app.run()

我可以用吗?提前致谢

python tensorflow image-recognition object-detection-api
1个回答
1
投票

这是出错了的数据,即以int类的标签。我不知道为什么你使用一个对象检测体系来分类的任务,但使用它,你需要准备的标签映射,构建类名称和整数ID之间的对应关系。见this example

这是在你的代码,顺便说一下:

# TO-DO replace this with label map
def class_text_to_int(row_label):
    if row_label != 0:
        return row_label
    else:
        None

所以,您需要:

  1. 为您的数据集将标签地图。见的例子here
  2. 从它创建一个label_dict:label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path)
  3. 用它来获得整数ID:classes.append(label_map_dict[row['class']])
© www.soinside.com 2019 - 2024. All rights reserved.