Quantcast
Channel: ValueError: Cannot feed value of shape () for Tensor 'input_example_tensor:0', which has shape '(?,)' - Stack Overflow
Viewing all articles
Browse latest Browse all 4

ValueError: Cannot feed value of shape () for Tensor 'input_example_tensor:0', which has shape '(?,)'

$
0
0

Why this error appear?

I cannot find similar to mine case with an answer with an explanation why that's happening. There are a lot of info there for such errors, but seems like it depends on a lot of reasons and for different cases, it can have different solutions.

So I am trying to load TensorFlow trained model, then convert it into TensorFlow Serving model format and that makes a prediction.

iris_data.py file from import bellow.

That's how I export my model (train already did, I just load it from disk):

import tensorflow as tf
import iris_data
from tensorflow.contrib import predictor

# Fetch the data
    (train_x, train_y), (test_x, test_y) = iris_data.load_data()

    # Feature columns describe how to use the input.
    my_feature_columns = []
    for key in train_x.keys():
        my_feature_columns.append(tf.feature_column.numeric_column(key=key))

    # Build 2 hidden layer DNN with 10, 10 units respectively.
    classifier = tf.estimator.DNNClassifier(
        feature_columns=my_feature_columns,
        # Two hidden layers of 10 nodes each.
        hidden_units=[10, 10],
        # The model must choose between 3 classes.
        n_classes=3,
        model_dir='G:\AI models')

    #converting into TensorFlow Serving model format 
    path = 'G:\AI models\serve'
    feature_spec = tf.feature_column.make_parse_example_spec(my_feature_columns)
    export_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
    servable_model_path = classifier.export_savedmodel(path, export_input_fn, as_text=True)

Here is how I try to get a prediction using TensorFlow Serving model:

 expected = ['Setosa', 'Versicolor', 'Virginica']
    predict_x = {
        'SepalLength': [5.1, 5.9, 6.9],
        'SepalWidth': [3.3, 3.0, 3.1],
        'PetalLength': [1.7, 4.2, 5.4],
        'PetalWidth': [0.5, 1.5, 2.1],
    }
path = 'G:\AI models\serve\\1519413839'
    predict_fn = predictor.from_saved_model(path)
    predictions = predict_fn(
        {"inputs": predict_x})

And finally get an error:

ValueError: Cannot feed value of shape () for Tensor 'input_example_tensor:0', which has shape '(?,)'

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images