tensorflow的一些知识

encoder = gdet.create_box_encoder(model_filename, batch_size=1)

class ImageEncoder(object):  # TODO ImageEncoder

    def __init__(self, checkpoint_filename, input_name="images",
                 output_name="features"):
        self.session = tf.Session()
        with tf.gfile.GFile(checkpoint_filename, "rb") as file_handle:  # TODO 2 学习tf这部分
            graph_def = tf.GraphDef()
            # tf.gfile.GFile(filename, mode)
            # 获取文本操作句柄,类似于python提供的文本操作open()函数,filename是要打开的文件名,
            # mode是以何种方式去读写,将会返回一个文本操作句柄。
            graph_def.ParseFromString(file_handle.read())
        tf.import_graph_def(graph_def, name="net")
        # 将图从graph_def导入到当前默认图中.
        # graph_def: 包含要导入到默认图中的操作的GraphDef proto。

        self.input_var = tf.get_default_graph().get_tensor_by_name(
            "net/%s:0" % input_name)
        self.output_var = tf.get_default_graph().get_tensor_by_name(
            "net/%s:0" % output_name)
        # print('self.input_var', self.input_var) Tensor("net/images:0", shape=(?, 128, 64, 3), dtype=uint8)
        # print('self.output_var', self.output_var)  Tensor("net/features:0", shape=(?, 128), dtype=float32)

        assert len(self.output_var.get_shape()) == 2
        assert len(self.input_var.get_shape()) == 4
        self.feature_dim = self.output_var.get_shape().as_list()[-1]
        self.image_shape = self.input_var.get_shape().as_list()[1:]
        # print('self.feature_dim', self.feature_dim) 128
        # print('第一个shape:', self.image_shape) 高宽为[128, 64, 3]

tf.GraphDef()

https://blog.csdn.net/zj360202/article/details/78539464

tf.import_graph_def(graph_def, name="net")
# 将图从graph_def导入到当前默认图中.
# graph_def: 包含要导入到默认图中的操作的GraphDef proto。

https://blog.csdn.net/qq_34106574/article/details/82686389

猜你喜欢

转载自blog.csdn.net/zjc910997316/article/details/85058487