def __init__(self): label_map_file = self.load_labelemap() label_map = label_map_util.load_labelmap(label_map_file) log.debug(label_map) categories = label_map_util.convert_label_map_to_categories( label_map, max_num_classes=NUM_CLASSES, use_display_name=True) self.__category_index = label_map_util.create_category_index( categories) self.__detection_graph = tf.Graph() #self.__feature_extractor = ExtractFeature(use_gpu=True) self.__color_extractor = ExtractColor(use_gpu=True) model_file = self.load_model() with self.__detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(model_file, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') with tf.device(GPU): config = tf.ConfigProto() config.gpu_options.allow_growth = True self.__sess = tf.Session(config=config, graph=self.__detection_graph) log.info('_init_ done')
def __init__(self): label_map = label_map_util.load_labelmap(OD_LABELS) log.debug(label_map) categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True) self.__category_index = label_map_util.create_category_index(categories) self.__detection_graph = tf.Graph() with self.__detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(OD_MODEL, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') self.__sess = tf.Session(graph=self.__detection_graph) self.image_feature = ExtractFeature() log.info('_init_ done')
def __init__(self): # Load categories curr_dir = os.path.dirname(os.path.realpath(__file__)) labels_file = curr_dir + '/label_map.pbtxt' num_classes = 14 label_map = label_map_util.load_labelmap(labels_file) categories = label_map_util.convert_label_map_to_categories( label_map, max_num_classes=num_classes, use_display_name=True) self.category_index = label_map_util.create_category_index(categories) # Load inference graph frozen_graph_file = curr_dir + '/inference_graph/frozen_inference_graph.pb' self.detection_graph = tf.Graph() with self.detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(frozen_graph_file, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') config = tf.ConfigProto() config.gpu_options.allow_growth = True self.sess = tf.Session(graph=self.detection_graph, config=config) # Input and output tensors self.image_tensor = self.detection_graph.get_tensor_by_name( 'image_tensor:0') self.detection_boxes = self.detection_graph.get_tensor_by_name( 'detection_boxes:0') self.detection_scores = self.detection_graph.get_tensor_by_name( 'detection_scores:0') self.detection_classes = self.detection_graph.get_tensor_by_name( 'detection_classes:0') self.num_detections = self.detection_graph.get_tensor_by_name( 'num_detections:0') self.debug = False
def __init__(self): # self.download_model() # Loading label map self.__api_instance = stylelens_index.ImageApi() self.__search = stylelens_search.SearchApi() label_map = label_map_util.load_labelmap(OD_LABELS) print(label_map) categories = label_map_util.convert_label_map_to_categories( label_map, max_num_classes=NUM_CLASSES, use_display_name=True) self.__category_index = label_map_util.create_category_index( categories) self.__detection_graph = tf.Graph() with self.__detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(OD_MODEL, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='') self.__sess = tf.Session(graph=self.__detection_graph) self.image_feature = feature_extract.ExtractFeature() print('_init_ done')
CURRENCY_UNIT = 'currency_unit' PRODUCT_URL = 'product_url' PRODUCT_NO = 'product_no' MAIN = 'main' NATION = 'nation' REDIS_IMAGE_CROP_QUEUE = 'bl:image:crop:queue' STR_BUCKET = "bucket" STR_STORAGE = "storage" STR_CLASS_CODE = "class_code" STR_NAME = "name" STR_FORMAT = "format" # Loading label map label_map = label_map_util.load_labelmap(OD_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) api_instance = stylelens_index.ImageApi() REDIS_SERVER = os.environ['REDIS_SERVER'] rconn = redis.StrictRedis(REDIS_SERVER) logging.basicConfig(filename='./log/main.log', level=logging.DEBUG) heart_bit = True def job():
file_name = os.path.basename(file.name) if 'frozen_inference_graph.pb' in file_name: tar_file.extract(file, os.getcwd()) # ## Load a (frozen) Tensorflow model into memory. detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef() 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 maps map indices to category names, so that when our convolution network predicts `5`, we know that this corresponds to `airplane`. Here we use internal utility functions, but anything that returns a dictionary mapping integers to appropriate string labels would be fine 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 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) # Size, in inches, of the output images. IMAGE_SIZE = (12, 8)