forked from aloyschen/tensorflow-yolo3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_pb.py
36 lines (33 loc) · 1.5 KB
/
read_pb.py
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
import os
import config
import argparse
import numpy as np
import colorsys
import tensorflow as tf
from yolo_predict import yolo_predictor
from PIL import Image, ImageFont, ImageDraw
from utils import letterbox_image, load_weights
with tf.Session() as sess:
image_path = "F:\\deeplearning_dataset\\new_ribbon\\split_imge\\1109_(98)_1.jpg"
##########数据准备阶段################
image = Image.open(image_path)
resize_image = letterbox_image(image, (416, 416))
image_data = np.array(resize_image, dtype = np.float32)
image_data /= 255.
image_data = np.expand_dims(image_data, axis = 0)
#####################################
pb_file_path = 'F:\\github_working\\version_2_190114\\alsochen-tensorflow-yolo3-threeoutput\\tensorflow-yolo3\\pb_file\\model.pb'
with tf.gfile.GFile(pb_file_path, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
pred_im_shape, pred_input_img, boxes, scores, classes = tf.graph_util.import_graph_def(graph_def, return_elements=['pred_im_shape:0', 'pred_input_img:0', 'predict/pred_boxes:0', 'predict/pred_scores:0', 'predict/pred_classes:0'])
out_boxes, out_scores, out_classes = sess.run(
[boxes, scores, classes],
feed_dict={
pred_input_img: image_data,
pred_im_shape: [image.size[1], image.size[0]]
})
print("class:\n")
print(out_classes)
print("class done\n")
print([out_boxes, out_scores, out_classes])