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.
6403 Discussions

Why is there an InvalidArgumentError: You must feed a value for placeholder tensor 'dense_1_input'

idata
Employee
2,049 Views

Hello team,

 

Not sure this is a duplicate from other issues, but I did not find any useful answer to this topic.

 

I am trying to use Keras to generate a trained model and to ultimately use it in the Movidius for inference.

 

For this, I am saving the model as TM_Model/tf_model.meta

 

After this I run the mvNCCompile command to generate a graph input file that could be used by the Movidius.

 

# Ubuntu 16.04.5 LTS mvNCCompile ./TF_Model/tf_model.meta -in dense_1/kernel -on activation_1/Softmax -o ./graph mvNCCompile v02.00, Copyright @ Intel Corporation 2017 InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'dense_1_input' with dtype float and shape [?,3072] [[Node: dense_1_input = Placeholder[dtype=DT_FLOAT, shape=[?,3072], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

 

I am using the cats and dogs example as it is documented in this url:

 

https://pyimagesearch.com/2016/09/26/a-simple-neural-network-with-python-and-keras/

 

The following python script represents this model and saves the data to TF_Model/tf_model.meta

 

Applying the output of this script to the mvNCCompile command, generates the InvalidArgumentError message.

 

# Run this application in a virtual environment # [venv] python catsdogs.py --dataset kaggle_dogs_vs_cats # kaggle_dogs_vs_cats directory contains the 25000 images (cats and dogs) # import the necessary packages from sklearn.preprocessing import LabelEncoder from sklearn.model_selection import train_test_split from keras.models import model_from_json from keras.models import Sequential from keras.layers import Activation from keras.optimizers import SGD from keras.layers import Dense from keras.utils import np_utils from keras import backend as K from imutils import paths import numpy as np import argparse import cv2 import os import tensorflow as tf def image_to_feature_vector(image, size=(32, 32)): return cv2.resize(image, size).flatten() # construct the arguments and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-d", "--dataset", required=True,help="path to input dataset") args = vars(ap.parse_args()) # grab the list of images that we'll be describing print("[INFO] describing images...") imagePaths = list(paths.list_images(args["dataset"])) # initialize the data matrix and labels list data = [] labels = [] # loop over the input images for (i, imagePath) in enumerate(imagePaths): image = cv2.imread(imagePath) label = imagePath.split(os.path.sep)[-1].split(".")[0] features = image_to_feature_vector(image) data.append(features) labels.append(label) if i > 0 and i % 1000 == 0: print("[INFO] processed {}/{}".format(i, len(imagePaths))) # encode the labels, converting them from strings to integers le = LabelEncoder() labels = le.fit_transform(labels) data = np.array(data) / 255.0 labels = np_utils.to_categorical(labels, 2) print("[INFO] constructing training/testing split...") (trainData, testData, trainLabels, testLabels) = train_test_split(data, labels, test_size=0.25, random_state=42) # define the architecture of the network model = Sequential() model.add(Dense(768, input_dim=3072, init="uniform", activation="relu")) model.add(Dense(384, activation="relu", kernel_initializer="uniform")) model.add(Dense(2)) model.add(Activation("softmax")) # train the model using SGD print("[INFO] compiling model...") sgd = SGD(lr=0.01) model.compile(loss="binary_crossentropy", optimizer=sgd, metrics=["accuracy"]) # epochs is set to 5 iso 50, to speed up a little. model.fit(trainData, trainLabels, epochs=5, batch_size=128, verbose=1) (loss, accuracy) = model.evaluate(testData, testLabels, batch_size=128, verbose=1) print("[INFO] loss={:.4f}, accuracy: {:.4f}%".format(loss,accuracy * 100)) K.set_learning_phase(0) # serialize model to JSON print("[INFO] saving model in json format (model.json)") model_json = model.to_json() with open("model.json", "w") as json_file: json_file.write(model_json) # serialize weights to HDF5 print("[INFO] saving weigths in h5 format (model.h5)") model.save_weights("model.h5") print("[INFO] Saving to TF_Model (TF_Model/tf_model)") saver = tf.train.Saver() sess = K.get_session() saver.save(sess, "./TF_Model/tf_model")

 

Any ideas to get this solved are very welcome, thanks !

0 Kudos
4 Replies
idata
Employee
1,333 Views

I just got exactly the same problem. Hope someone can help.

0 Kudos
idata
Employee
1,333 Views

Did anybody figured out why this error is coming. I am also stuck in this

0 Kudos
idata
Employee
1,333 Views

Hi

 

Please let me know if there is solution for this problem. I am stuck at this problem.

0 Kudos
GWang48
Beginner
1,333 Views

For NCSDK 1.X, this solution works for me:

edit ncsdk source in 

/usr/local/bin/ncsdk/Controllers/TensorFlowParser.py

 line 1059, add a feed_dict to eval:

# desired_shape = node.inputs[1].eval()

desired_shape = node.inputs[1].eval(feed_dict={inputnode + ':0' : input_data})

Enjoy ;-)

0 Kudos
Reply