Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

OPENVINO model optimizer - gives errors

Nettleton__David
Beginner
703 Views

Hi,

We are trying to process a trained model (tensorflow 1.14) using mo_tf.py  and are getting bugs.

The following is the python script we use to train and save the model and after that the bugs we are getting. It seems to complain about:

Shape [-1] is not fully defined for output 0 of "Placeholder_1".

If you could indicate what we have to change in our python script that would be great !

Thanks a lot and regards,

David.

/******************** PYTHON SCRIPT TO TRAIN AND SAVE THE MODEL ******************/

/*************** start up **************/
activate tensorflow_cpu
python
import tensorflow as tf

/*************** read in data **************/
def load_data(data_directory):
    directories = [d for d in os.listdir(data_directory) 
                   if os.path.isdir(os.path.join(data_directory, d))]
    labels = []
    images = []
    for d in directories:
        label_directory = os.path.join(data_directory, d)
        file_names = [os.path.join(label_directory, f) 
                      for f in os.listdir(label_directory) 
                      if f.endswith(".ppm")]
        for f in file_names:
            images.append(imageio.imread(f))
            labels.append(int(d))
    return images, labels

import os
import skimage
ROOT_PATH = "C:\\Users\\openmind"
train_data_directory = os.path.join(ROOT_PATH, "TrafficSigns\\Training")
test_data_directory = os.path.join(ROOT_PATH, "TrafficSigns\\Testing")
import imageio
images, labels = load_data(data_directory = train_data_directory)

/*************** rescale **************/
from skimage import transform
images28 = [transform.resize(image, (28, 28)) for image in images]

/*************** greyscale **************/
from skimage.color import rgb2gray
import numpy as np
images28 = np.array(images28)
images28 = rgb2gray(images28)

/*************** define neural network **************/
x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])
y = tf.placeholder(dtype = tf.int32, shape = [None])
import keras
import keras.utils
from keras import utils as np_utils
images_flat = tf.keras.layers.Flatten()(x)
logits = tf.contrib.layers.fully_connected(images_flat, 62, tf.nn.relu)
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels = y, 
                                                                    logits = logits))
train_op = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
correct_pred = tf.argmax(logits, 1)
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))

/*************** train neural network **************/ (ok!)
tf.set_random_seed(1234)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
graph = tf.Graph().as_default()

for i in range(201):
        print('EPOCH', i)
        _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: images28, y: labels})
        if i % 10 == 0:
            print("Loss: ", loss)
        print('DONE WITH EPOCH')

/*************** save the model (.data, .meta, .index, checkpoint, .pbtxt **************/
saver = tf.train.Saver()
saver.save(sess, 'belgiantrafficsigns.ckpt')
tf.train.write_graph(sess.graph.as_graph_def(), '.', 'belgiantrafficsigns.pbtxt', as_text=True)

/*************** clean up and leave **************/
sess.close()

 

/******************** RUN OPENVINO MODEL OPTIMIZER  (mo_tf.py) ******************/

(tensorflow_cpu) c:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer>python mo_tf.py --input_meta_graph belgiantrafficsigns.meta
Model Optimizer arguments:
Common parameters:
        - Path to the Input Model:      None
        - Path for generated IR:        c:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\.
        - IR output name:       belgiantrafficsigns
        - Log level:    ERROR
        - Batch:        Not specified, inherited from the model
        - Input layers:         Not specified, inherited from the model
        - Output layers:        Not specified, inherited from the model
        - Input shapes:         Not specified, inherited from the model
        - Mean values:  Not specified
        - Scale values:         Not specified
        - Scale factor:         Not specified
        - Precision of IR:      FP32
        - Enable fusing:        True
        - Enable grouped convolutions fusing:   True
        - Move mean values to preprocess section:       False
        - Reverse input channels:       False
TensorFlow specific parameters:
        - Input model in text protobuf format:  False
        - Path to model dump for TensorBoard:   None
        - List of shared libraries with TensorFlow custom layers implementation:        None
        - Update the configuration file with input/output node names:   None
        - Use configuration file used to generate the model with Object Detection API:  None
        - Operations to offload:        None
        - Patterns to offload:  None
        - Use the config file:  None
Model Optimizer version:        2019.2.0-436-gf5827d4
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\david.nettleton\AppData\Roaming\Python\Python36\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
WARNING: Logging before flag parsing goes to stderr.
E1115 15:31:17.943851  1056 infer.py:160] Shape [-1] is not fully defined for output 0 of "Placeholder_1". Use --input_shape with positive integers to override model input shapes.
E1115 15:31:17.943851  1056 infer.py:180] Cannot infer shapes or values for node "Placeholder_1".
E1115 15:31:17.943851  1056 infer.py:181] Not all output shapes were inferred or fully defined for node "Placeholder_1".
 For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question #40.
E1115 15:31:17.943851  1056 infer.py:182]
E1115 15:31:17.943851  1056 infer.py:183] It can happen due to bug in custom shape infer function <function Parameter.__init__.<locals>.<lambda> at 0x000001EE2E68A730>.
E1115 15:31:17.943851  1056 infer.py:184] Or because the node inputs have incorrect values/shapes.
E1115 15:31:17.943851  1056 infer.py:185] Or because input shapes are incorrect (embedded to the model or passed via --input_shape).
E1115 15:31:17.943851  1056 infer.py:194] Run Model Optimizer with --log_level=DEBUG for more information.
E1115 15:31:17.943851  1056 main.py:307] Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.middle.PartialInfer.PartialInfer'>): Stopped shape/value propagation at "Placeholder_1" node.
 For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question #38.
 

0 Kudos
2 Replies
Roy_A_Intel
Employee
703 Views

Hi @David,

Seems like you are using OpenVINO 2019 R2 version, could you update to R3 and let me know if you encounter the same error.

 

Regards

Roy

0 Kudos
Nettleton__David
Beginner
703 Views

Hi Roy,

Thanks for this information, we will try updating OpenVINO, rerun and let you know the result.

Best regards,

David

0 Kudos
Reply