Deep-Alignment-Network-A-convolutional-neural-network-for-robust-face-alignment icon indicating copy to clipboard operation
Deep-Alignment-Network-A-convolutional-neural-network-for-robust-face-alignment copied to clipboard

Freezing a model

Open Onotoko opened this issue 6 years ago • 13 comments

Hi zjjMaiMai, After I trained a model I have full check point file and graph.pbtxt, but when I want to freeze model, I cannot execute it. I flow this: bazel build tensorflow/tools:freeze_graph bazel-bin/tensorflow/tools/freeze_graph
--input_graph=/tmp/model/graph.pbtxt
--input_checkpoint=/tmp/model/model.ckpt-1000
--output_graph=/tmp/frozen_graph.pb
--output_node_names="Sotfmax"
But it is error:

tensorflow.python.framework.errors_impl.NotFoundError: Op type not registered 'ImageProjectiveTransform' in binary running on diffdeep-server. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) tf.contrib.resampler should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed

Please kindly help me, Thanks!

Onotoko avatar Jul 02 '18 10:07 Onotoko

do you solve this question?

maidanglao990 avatar Jan 28 '19 09:01 maidanglao990

I met the same problem,and bother me for a long time.

maidanglao990 avatar Jan 28 '19 09:01 maidanglao990

Hi @maidanglao99, now I do not work on this project. Hope you can fix it :)

Onotoko avatar Jan 30 '19 09:01 Onotoko

请问下,这个问题解决了吗 我也遇到了这个问题

oftenliu avatar Feb 15 '19 07:02 oftenliu

import tensorflow as tf import os import shutil import json from DAN_V2 import vgg16_model_fn import numpy as np

""" The purpose of this script is to export the inference graph as a SavedModel.

Also it creates a .pb frozen inference graph. """

OUTPUT_FOLDER = 'export/' # for savedmodel PB_FILE_PATH = 'model.pb' GPU_TO_USE = '1' DATA_DIR = './trainset'

WIDTH, HEIGHT = 112,112 def read_dataset_info(data_dir): mean_shape = np.loadtxt(os.path.join(data_dir,'mean_shape.ptv'),dtype=np.float32,delimiter=',') imgs_mean = np.loadtxt(os.path.join(data_dir,'imgs_mean.ptv'),dtype=np.float32,delimiter=',') imgs_std = np.loadtxt(os.path.join(data_dir,'imgs_std.ptv'),dtype=np.float32,delimiter=',') return mean_shape.astype(np.float32) ,imgs_mean.astype(np.float32),imgs_std.astype(np.float32)

def export_savedmodel(): mean_shape,imgs_mean,imgs_std = read_dataset_info(DATA_DIR) config = tf.ConfigProto() #config.gpu_options.visible_device_list = GPU_TO_USE run_config = tf.estimator.RunConfig() run_config = run_config.replace( session_config=config ) estimator = tf.estimator.Estimator(vgg16_model_fn, model_dir='model_dir',config=run_config, params={ 'dan_stage':2, 'num_lmark':98, 'data_format': 'channels_last', 'batch_size': 1, 'multi_gpu': 0, 'mean_shape':mean_shape, 'imgs_mean':imgs_mean, 'imgs_std':imgs_std })

def serving_input_receiver_fn():
    images = tf.placeholder(dtype=tf.uint8, shape=[None, HEIGHT, WIDTH, 1], name='images')
    features = tf.to_float(images) * (1.0/255.0)
    return tf.estimator.export.TensorServingInputReceiver(features=features, receiver_tensors={'images': images})

shutil.rmtree(OUTPUT_FOLDER, ignore_errors=True)
os.mkdir(OUTPUT_FOLDER)
estimator.export_savedmodel(OUTPUT_FOLDER, serving_input_receiver_fn)

def convert_to_pb():

subfolders = os.listdir(OUTPUT_FOLDER)
assert len(subfolders) == 1
last_saved_model = os.path.join(OUTPUT_FOLDER, subfolders[0])

graph = tf.Graph()
config = tf.ConfigProto()
#config.gpu_options.visible_device_list = GPU_TO_USE

with graph.as_default():
    with tf.Session(graph=graph, config=config) as sess:
        tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], last_saved_model)

        # output ops
        keep_nodes = ['landmarks']

        input_graph_def = tf.graph_util.convert_variables_to_constants(
            sess, graph.as_graph_def(),
            output_node_names=keep_nodes
        )
        output_graph_def = tf.graph_util.remove_training_nodes(
            input_graph_def, protected_nodes=keep_nodes
        )
        #print(output_graph_def)
        with tf.gfile.GFile(PB_FILE_PATH, 'wb') as f:
            f.write(output_graph_def.SerializeToString())

        print('%d ops in the final graph.' % len(output_graph_def.node))

tf.logging.set_verbosity('INFO') #export_savedmodel() #convert_to_pb()

print("start================================== \n") with tf.gfile.GFile("model.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) print([n.name for n in graph_def.node]) graph = tf.Graph() #print(graph)

config_proto = tf.ConfigProto() sess = tf.Session(graph=graph, config=config_proto)

with graph.as_default(): tf.import_graph_def(graph_def, name='import')

print("okokokokokokok") input_image = graph.get_tensor_by_name('import/images:0') output = graph.get_tensor_by_name('import/landmarks:0')

oftenliu avatar Feb 15 '19 07:02 oftenliu

上面是我create pb的代码

oftenliu avatar Feb 15 '19 07:02 oftenliu

上面是我create pb的代码

您好,可以把creat.pb代码分享给我吗?或者上传到你的github上? 由于缩进问题使我在复现的时候非常困扰

kelisiya avatar Feb 25 '19 11:02 kelisiya

上面是我create pb的代码 请问您的代码是如何解决 AssertionError: landmarks is not in graph 这个问题的? 我在使用了您的代码后出现了这个错误

kelisiya avatar Feb 26 '19 07:02 kelisiya

I met the same problem,and bother me for a long time. do you solve this question?

kelisiya avatar Feb 28 '19 11:02 kelisiya

兄弟,我还没解决呢,代码还需要吗? 目前直接用ckpt了

oftenliu avatar Feb 28 '19 13:02 oftenliu

兄弟,我还没解决呢,代码还需要吗? 目前直接用ckpt了 让我参考一下哇大佬,我邮箱:[email protected]

kelisiya avatar Feb 28 '19 13:02 kelisiya

明天发你

oftenliu avatar Feb 28 '19 13:02 oftenliu

请问你们的测试代码可以发一份吗。邮箱[email protected]

destiny311 avatar Jul 04 '19 12:07 destiny311