Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
306 Views

How to compile customized yolo network with movidius? Compiling YOLO network fails with value error cannot reshape array of size 4056 into shape (1,1,1)

I have created inference model of yolo on tensorflow 1.13.1 and trying to compile to generate movidius graph. I have 3 classes and 3 anchor boxes predicted from network. However, I am facing the following error on compiling:

res.shape: (1, 13, 13, 3, 8)

Traceback (most recent call last):

 File "/usr/local/bin/mvNCCompile", line 206, in <module>

  create_graph(args.network, args.image, args.inputnode, args.outputnode, args.outfile, args.nshaves, args.inputsize, args.weights, args.explicit_concat, args.ma2480, args.scheduler, args.new_parser, args.cpp, args)

 File "/usr/local/bin/mvNCCompile", line 185, in create_graph

  load_ret = load_network(args, parser, myriad_config)

 File "/usr/local/bin/ncsdk/Controllers/Scheduler.py", line 146, in load_network

  parse_ret = parse_tensor(arguments, myriad_conf)

 File "/usr/local/bin/ncsdk/Controllers/TensorFlowParser.py", line 1751, in parse_tensor

  res = res.reshape(1, 1, res.shape[0])

ValueError: cannot reshape array of size 4056 into shape (1,1,1)

 

Tags (3)
0 Kudos
3 Replies
Moderator
68 Views

Hi AAhma26,

Are you using NCSDK2? Can you please attach your model and I can take a look at it.

 

Sincerely,

Sahira

0 Kudos
Beginner
68 Views

Hello Sahira,

 

Thanks for your response. I am using Tensorflow 1.9.0 and also 1.13.0 with Movidius 2.10 .

I am attaching my model below [yolo_net] method. I tried compiling it again but instead of returning 13x13x3x8 shape from my model I combined these array and changed the last line of my model to

y = tf.reshape(net, shape=(-1, 13* 13* (len(anchor)//2)* (num_class+ 5)), name='output') which compiled successfully. Am I doing it the correct way?

 

import tensorflow as tf

import yolo.config as config

import cv2

import numpy as np   

 

def maxpool_layer(x,size,stride,name):

with tf.name_scope(name):

x = tf.layers.max_pooling2d(x, size, stride, padding='SAME')

 

return x

 

def conv_layer(x, kernel, depth, train_logical,name):

 

with tf.variable_scope(name):

x = tf.layers.conv2d(x, depth, kernel, padding='SAME', kernel_initializer=tf.contrib.layers.xavier_initializer_conv2d(), bias_initializer=tf.zeros_initializer())

x = tf.layers.batch_normalization(x, training=train_logical, momentum=0.99, epsilon=0.001, center=True, scale=True)

return x

 

 

def yolo_net(x, train_logical=False):

 

x = conv_layer(x, (3, 3), 32, train_logical, 'conv1')

x = maxpool_layer(x, (2, 2), (2, 2), 'maxpool1')

x = conv_layer(x, (3, 3), 64, train_logical, 'conv2')

x = maxpool_layer(x, (2, 2), (2, 2), 'maxpool2')

x = conv_layer(x, (3, 3), 128, train_logical, 'conv3')

x = conv_layer(x, (1, 1), 64, train_logical, 'conv4')

x = conv_layer(x, (3, 3), 128, train_logical, 'conv5')

x = maxpool_layer(x, (2, 2), (2, 2), 'maxpool5')

 

x = conv_layer(x, (3, 3), 256, train_logical, 'conv6')

x = conv_layer(x, (1, 1), 128, train_logical, 'conv7')

x = conv_layer(x, (3, 3), 256, train_logical, 'conv8')

x = maxpool_layer(x, (2, 2), (2, 2), 'maxpool8')

 

x = conv_layer(x, (3, 3), 512, train_logical, 'conv9')

x = conv_layer(x, (1, 1), 256, train_logical, 'conv10')

x = conv_layer(x, (3, 3), 512, train_logical, 'conv11')

x = conv_layer(x, (1, 1), 256, train_logical, 'conv12')

 

x = maxpool_layer(x, (2, 2), (2, 2), 'maxpool13')

x = conv_layer(x, (3, 3), 1024, train_logical, 'conv14')

x = conv_layer(x, (1, 1), 512, train_logical, 'conv15')

x = conv_layer(x, (3, 3), 1024, train_logical, 'conv16')

x = conv_layer(x, (1, 1), 512, train_logical, 'conv17')

x = conv_layer(x, (3, 3), 1024, train_logical, 'conv18')

 

x = conv_layer(x, (3, 3), 1024, train_logical, 'conv19')

x = conv_layer(x, (3, 3), 1024, train_logical, 'conv20')

x = conv_layer(x, (1, 1), (len(anchor)//2) * (num_class + 5), train_logical, 'conv23')

   

                        #?,13,13,3,8

y = tf.reshape(x, shape=(-1, 13, 13, len(anchor)//2, num_class+ 5), name='y')

return y

 

def sigmoid(x):

  return 1./(1. + np.exp(-x))

 

def softmax(x):

  e_x = np.exp(x - np.max(x))

  out = e_x/e_x.sum()

  return out

 

##########Main Starts Here################

input_image=cv2.imread('./person_1.jpg')

actual_height,actual_width,_=input_image.shape

input_image=cv2.resize(input_image,(config.IMAGE_H,config.IMAGE_W))

image=tf.placeholder(tf.float32,shape=[1,config.IMAGE_SIZE,config.IMAGE_SIZE,3],name='Input')

saver = tf.train.Saver(tf.global_variables())

with tf.Session() as sess:

  sess.run(tf.global_variables_initializer())

  sess.run(tf.local_variables_initializer())

  #saver.restore(sess,'./yolo_data_model')#meta file stored during training, Uncomment to save Inference Model

saver.restore(sess,'.'+'/yolo_inference') #Generated Inference model, Comment if creating Inference Model

  print('model loaded')

  prediction=sess.run(y_conv=yolo_net(image),feed_dict={image:input_image})#Comment if creating Inference Model

  #read previously saved network

  #saver.save(sess,'./output/NN.ckpt')#Uncomment if creating Inference model

  tf.train.write_graph(sess.graph_def,"./output/","NN.pb",as_text=False)#Uncomment if creating Inference model

 

 

0 Kudos
Moderator
68 Views

Hi AAhma26,

 

I think y = tf.reshape(net, shape=(-1, 13* 13* (len(anchor)//2)* (num_class+ 5)), name='output') is correct. Please let me know if you have any further questions.

 

Sincerely,

Sahira

0 Kudos