SSD Mobile netv1的实现
主要是跟着https://www.cnblogs.com/White-xzx/p/9503203.html来做的,问题在于训练之后的检测,跑通了但是没有框出现,结合终端的结果我觉得是训练参数的问题,原blog中检测代码里有点小问题,已订正如下:
# -*- coding: utf-8 -*-
import os
from PIL import Image
import time
import tensorflow as tf
from PIL import Image
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import zipfile
import time
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
# plt.switch_backend('Agg')
from utils import label_map_util
from utils import visualization_utils as vis_util
PATH_TO_TEST_IMAGES = "D:\\ssd_mobilenetv1\\test_images\\"
MODEL_NAME = 'D:/ssd_mobilenetv1/data'
PATH_TO_CKPT = MODEL_NAME + '/exported_model_directory/frozen_inference_graph.pb'
PATH_TO_LABELS = MODEL_NAME+'/label_map.pbtxt'
NUM_CLASSES = 1
PATH_TO_RESULTS = "D:\\ssd_mobilenetv1\\results\\"
def load_image_into_numpy_array(image):
(im_width, im_height) = image.size
return np.array(image.getdata()).reshape((im_height, im_width, 3)).astype(np.uint8)
def save_object_detection_result():
IMAGE_SIZE = (12, 8)
# Load a (frozen) Tensorflow model into memory.
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
# loading ckpt file to graph
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
# Loading label map
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)
# Helper code
with detection_graph.as_default():
with tf