在test.py中可以通过如下代码直接生成带weight的pb文件,也可以通过tf官方的freeze_graph.py将ckpt转为pb文件。
constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def,['net_loss/inference/encode/conv_output/conv_output'])
with tf.gfile.FastGFile('net_model.pb', mode='wb') as f:
f.write(constant_graph.SerializeToString())
tf1.0中通过带weight的pb文件与get_tensor_by_name函数可以获取每一层的输出
import os
import os.path as ops
import argparse
import time
import math
import tensorflow as tf
import glob
import numpy as np
import matplotlib.pyplot as plt
import cv2
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
gragh_path = './model.pb'
image_path = './lvds1901.JPG'
inputtensorname = 'input_tensor:0'
tensorname = 'loss/inference