Hi,
I use the following github provides .meta file to convert to dlc
The network architecture is inception-resnet-v1
https://github.com/davidsandberg/facenet
In snpe1.15.0, the command:
snpe-tensorflow-to-dlc --graph /model_20180402-114759/20180402-114759.meta --input_dim 'input' '160,160,3' --out_node 'embeddings' --dlc 20180402-114759.dlc
But I got the following errors:
2018-07-11 11:22:23,979 - 126 - ERROR - Encountered Error: as_list() is not defined on an unknown TensorShape.
Traceback (most recent call last):
File "/root/snpe-sdk/bin/x86_64-linux-clang/snpe-tensorflow-to-dlc", line 120, in main
converter.convert(args.dlc, args.model_version, converter_command)
File "/root/snpe-sdk/lib/python/converters/tensorflow/converter.py", line 298, in convert
self._graph_helper = GraphHelper(self._model.session, self._model, self._ops)
File "/root/snpe-sdk/lib/python/converters/tensorflow/util.py", line 125, in __init__
self._placeholders_stubs_map = self._create_placeholders_tensors(session)
File "/root/snpe-sdk/lib/python/converters/tensorflow/util.py", line 140, in _create_placeholders_tensors
shape = tensor.get_shape().as_list()
File "/root/tensorflow_17/local/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 820, in as_list
raise ValueError("as_list() is not defined on an unknown TensorShape.")
ValueError: as_list() is not defined on an unknown TensorShape.
I found there are some customized layers should be defined if I want to convert.
(<tf.Tensor 'import/phase_train:0' shape=<unknown> dtype=bool>,)
(<tf.Tensor 'import/batch_size:0' shape=<unknown> dtype=int32>,)
I can input " -i 'batch_size' '1,1,1' " to define 'batch_size" layer, but I want to skip "phase_train" layer.
Is there any method to skip the "phase_train" layer when converting dlc?
Please help to provide more information.
Thanks.
About the PB file, we run Google transform tool to optimize it and modify SNPE-SDK source code to set "phase_train" layer parameter.
However, there are still some problems when converting DLC.
The CPU is overloading and then the computer crashes if we do not kill the converting process.
Here is the computer information.
[PC1]
CPU: Intel i7-4790
Memory: 16GB
Graphics: GTX 760
Tensorflow: 1.0, 1.5, 1.7
[PC2]
CPU: Intel E5-1620
Memory: 64GB
Graphics: GTX 1060
Tensorflow: 1.0, 1.5, 1.7
The process did not print any error logs. Thus, we don't know how to do the next step.
Please help to provide any suggestion.
Thanks.
Hi johnson2_chen,
Just checking are you able to solve above issue. Because i am also facing same issue.
2019-09-09 23:14:05,675 - 109 - ERROR - Encountered Error: as_list() is not defined on an unknown TensorShape.
Traceback (most recent call last):
Download pre-trained model and unzip it to model_pre_trained/ directory and also create a directory model_inference.
Make sure you have python greater than 3.4 version.
Run this file(eval.py) on pre-trained model, would generate model for inference.
< code >
import tensorflow as tf
from src.models import inception_resnet_v1
import sys
import click
from pathlib import Path
@click.command()
@click.argument('training_checkpoint_dir', type=click.Path(exists=True, file_okay=False, resolve_path=True))
@click.argument('eval_checkpoint_dir', type=click.Path(exists=True, file_okay=False, resolve_path=True))
def main(training_checkpoint_dir, eval_checkpoint_dir):
traning_checkpoint = Path(training_checkpoint_dir) / "model-20180402-114759.ckpt-275"
eval_checkpoint = Path(eval_checkpoint_dir) / "imagenet_facenet.ckpt"
data_input = tf.placeholder(name='input', dtype=tf.float32, shape=[None, 160, 160, 3])
output, _ = inception_resnet_v1.inference(data_input, keep_probability=0.8, phase_train=False, bottleneck_layer_size=512)
output = tf.identity(output, name='output')
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
saver = tf.train.Saver()
saver.restore(sess, traning_checkpoint.as_posix())
save_path = saver.save(sess, eval_checkpoint.as_posix())
print("Model saved in file: %s" % save_path)
if __name__ == "__main__":
main()
< /code >
now run the freeze_graph.py in facenet to convert to frozen protobuf without phase_train layer then convert to dlc
Download pre-trained model and unzip it to model_pre_trained/ directory and also create a directory model_inference.
Make sure you have python greater than 3.4 version.
Run this file(eval.py) on pre-trained model, would generate model for inference.
< code >
import tensorflow as tf
from src.models import inception_resnet_v1
import sys
import click
from pathlib import Path
@click.command()
@click.argument('training_checkpoint_dir', type=click.Path(exists=True, file_okay=False, resolve_path=True))
@click.argument('eval_checkpoint_dir', type=click.Path(exists=True, file_okay=False, resolve_path=True))
def main(training_checkpoint_dir, eval_checkpoint_dir):
traning_checkpoint = Path(training_checkpoint_dir) / "model-20180402-114759.ckpt-275"
eval_checkpoint = Path(eval_checkpoint_dir) / "imagenet_facenet.ckpt"
data_input = tf.placeholder(name='input', dtype=tf.float32, shape=[None, 160, 160, 3])
output, _ = inception_resnet_v1.inference(data_input, keep_probability=0.8, phase_train=False, bottleneck_layer_size=512)
output = tf.identity(output, name='output')
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
saver = tf.train.Saver()
saver.restore(sess, traning_checkpoint.as_posix())
save_path = saver.save(sess, eval_checkpoint.as_posix())
print("Model saved in file: %s" % save_path)
if __name__ == "__main__":
main()
< /code >
now run the freeze_graph.py in facenet to convert to frozen protobuf without phase_train layer then convert to dlc