0

Tensorflow Object Detection APIからssd-inception-v2モデルをトレーニングする必要があります。私が使用したい訓練データセットは、作物自体がバウンディングボックスであるため、バウンディングボックスなしでサイズの異なるトリミングされたイメージの束です。TensorFlowオブジェクト検出API(トレーニングデータセットとして画像作物を使用)

def dict_to_tf_example(imagepath, label): 
    image = Image.open(imagepath) 
    if image.format != 'JPEG': 
     print("Skipping file: " + imagepath) 
     return 
    img = np.array(image) 
    with tf.gfile.GFile(imagepath, 'rb') as fid: 
     encoded_jpg = fid.read() 
    # The reason to store image sizes was demonstrated 
    # in the previous example -- we have to know sizes 
    # of images to later read raw serialized string, 
    # convert to 1d array and convert to respective 
    # shape that image used to have. 
    height = img.shape[0] 
    width = img.shape[1] 
    key = hashlib.sha256(encoded_jpg).hexdigest() 
    # Put in the original images into array 
    # Just for future check for correctness 

    xmin = [5.0/100.0] 
    ymin = [5.0/100.0] 
    xmax = [95.0/100.0] 
    ymax = [95.0/100.0] 
    class_text = [label['name'].encode('utf8')] 
    classes = [label['id']] 
    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(imagepath.encode('utf8')), 
     'image/source_id': dataset_util.bytes_feature(imagepath.encode('utf8')), 
     'image/encoded': dataset_util.bytes_feature(encoded_jpg), 
     'image/key/sha256': dataset_util.bytes_feature(key.encode('utf8')), 
     'image/format': dataset_util.bytes_feature('jpeg'.encode('utf8')),   
     'image/object/class/text': dataset_util.bytes_list_feature(class_text), 
     'image/object/class/label': dataset_util.int64_list_feature(classes), 
     'image/object/bbox/xmin': dataset_util.float_list_feature(xmin), 
     'image/object/bbox/xmax': dataset_util.float_list_feature(xmax), 
     'image/object/bbox/ymin': dataset_util.float_list_feature(ymin), 
     'image/object/bbox/ymax': dataset_util.float_list_feature(ymax) 
    })) 

    return example 


def main(_): 

    data_dir = FLAGS.data_dir 
    output_path = os.path.join(data_dir,FLAGS.output_path + '.record') 
    writer = tf.python_io.TFRecordWriter(output_path) 
    label_map = label_map_util.load_labelmap(FLAGS.label_map_path) 
    categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=80, use_display_name=True) 
    category_index = label_map_util.create_category_index(categories) 
    category_list = os.listdir(data_dir) 
    gen = (category for category in categories if category['name'] in category_list) 
    for category in gen: 
    examples_path = os.path.join(data_dir,category['name']) 
    examples_list = os.listdir(examples_path) 
    for example in examples_list: 
     imagepath = os.path.join(examples_path,example) 

     tf_example = dict_to_tf_example(imagepath,category) 
     writer.write(tf_example.SerializeToString()) 
#  print(tf_example) 

    writer.close() 

バウンディングボックスは、ハード画像全体を網羅符号化される:

私は次のようにTFRecordsを生成するために応じてバウンディングボックスと分類部分を置換create_pascal_tf_record.py例に従いました。ラベルは対応するディレクトリに応じて与えられます。私はラベル付けのためにmscoco_label_map.pbxtを使い、パイプラインのベースとしてssd_inception_v2_pets.configを使用しています。

jupyterノートブックの例で使用するモデルを訓練してフリーズしました。しかし、最終的な結果は画像全体を囲む単一のボックスです。何がうまくいかなかったのか?

答えて

1

オブジェクト検出アルゴリズム/ネットワークは、多くの場合、バウンディングボックスとクラスの位置を予測することによって動作します。このため、トレーニングデータにはバウンディングボックスのデータが含まれている必要があります。常に画像のサイズであるバウンディングボックスを使用してモデルにトレーニングデータを入力することで、常に画像の輪郭を描く箱を含むガーベッジの予測を得ることができます。

これはトレーニングデータの問題のようです。トリミングされた画像を与えるのではなく、注釈付きのオブジェクトを含む完全な画像/シーンを与えるべきです。あなたは基本的にこの時点でクラシファイアをトレーニングしています。

トリミングしていない正しいスタイルの画像でトレーニングを試してみましょう。

関連する問題