Forums - Convert inception_resnet_v1 network to dlc

5 posts / 0 new
Last post
Convert inception_resnet_v1 network to dlc
johnson2_chen
Join Date: 4 Jul 18
Posts: 2
Posted: Wed, 2018-07-11 04:36

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.

 

  • Up0
  • Down0
johnson2_chen
Join Date: 4 Jul 18
Posts: 2
Posted: Tue, 2018-07-17 22:12

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.

  • Up0
  • Down0
sanjay.1987saini
Join Date: 6 Aug 19
Posts: 6
Posted: Mon, 2019-09-09 10:47

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):

  File "/home/saini/deeplearning/SNPE/snpe-1.29.0.456/bin/x86_64-linux-clang/snpe-tensorflow-to-dlc", line 103, in main
    converter.convert(args.dlc, args.copyright_file, args.model_version, converter_command)
  File "/home/saini/deeplearning/SNPE/snpe-1.29.0.456/lib/python/snpe/converters/tensorflow/converter.py", line 302, in convert
    self._graph_helper = GraphHelper(self._model.session, self._model, self._ops)
  File "/home/saini/deeplearning/SNPE/snpe-1.29.0.456/lib/python/snpe/converters/tensorflow/util.py", line 117, in __init__
    self._placeholders_stubs_map = self._create_placeholders_tensors(session, input_names)
  File "/home/saini/deeplearning/SNPE/snpe-1.29.0.456/lib/python/snpe/converters/tensorflow/util.py", line 133, in _create_placeholders_tensors
    shape = tensor.get_shape().as_list()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 1159, in as_list
    raise ValueError("as_list() is not defined on an unknown TensorShape.")
ValueError: as_list() is not defined on an unknown TensorShape.
 

 

  • Up0
  • Down0
adarshksudarshan
Join Date: 25 Jun 20
Posts: 2
Posted: Mon, 2020-06-29 13:53

 

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.


  python3 eval.py model_pretrained model_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

  • Up0
  • Down0
adarshksudarshan
Join Date: 25 Jun 20
Posts: 2
Posted: Mon, 2020-06-29 13:55

 

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.


  python3 eval.py model_pretrained model_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

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.