我训练了一个 ssd_mobilenet_v1 模型来检测静态灰度图像中的小物体。
现在我想确定诸如物体的水平角度之类的东西。如何将对象“提取”为图像或图像阵列以进行进一步的几何研究?
这是我从 Github 上的 Tensorflow 对象检测 API 更改的 object_detection_tutorial.ipynb 文件的版本(原始版本可以在这里找到:https : //github.com/tensorflow/models/tree/master/research/object_detection)
代码:
进口
mport numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
对象检测导入
from utils import label_map_util
from utils import visualization_utils as vis_util
变量
# What model to download.
MODEL_NAME = 'shard_graph_ssd'
# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_FROZEN_GRAPH = MODEL_NAME + '/frozen_inference_graph.pb'
# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('data', 'label_map.pbtxt')
NUM_CLASSES = 1
将(冻结的)Tensorflow 模型加载到内存中。
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
加载标签图
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)
斯蒂芬大帝
相关分类