profile
viewpoint

Ask questionsTypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph.

### This is my code in python

from flask import Flask from flask_restful import Api, Resource, reqparse

app = Flask(name) api = Api(app)

import os import json import matplotlib.pyplot as plt import matplotlib.image as mpimg import logging import tensorflow as tf from keras import backend as K

from collections import Counter

import pandas as pd import numpy as np

from keras.models import load_model

from keras.preprocessing.image import array_to_img, img_to_array, load_img from scipy.misc import imresize

from PIL import Image

users = [ { "name": "Nicholas", "age": 42, "occupation": "Network Engineer",

},
{
    "name": "Elvin",
    "age": 32,
    "occupation": "Doctor"
   
},
{
    "name": "Jass",
    "age": 22,
    "occupation": "Web Developer"
  
}

]

class User(Resource): def get(self, name): for user in users: if(name == user["name"]): return user, 200 return "User not found", 404

def post(self, name):
    K.clear_session()
    parser = reqparse.RequestParser()
    parser.add_argument("image")
    #get the image
    model = load_model('C:/Users/ASUS/Downloads/mse-04-0.0877.h5')
    img_height, img_width, channels = 350, 350, 3

    img = load_img('C:/xampp/htdocs/faceD/image/logo.png')

    img = imresize(img, size=(img_height, img_width))	  
    test_x = img_to_array(img).reshape(img_height, img_width, channels) 
    test_x = test_x / 255.
    test_x = test_x.reshape((1,) + test_x.shape)
    predicted = model.predict(test_x)

    return{
        "name": "Nicholas",
        "age": 42,
        "occupation": "Network Engineer",
        "prediction": str(predicted[0][0])

}, 201


def put(self, name):
    parser = reqparse.RequestParser()
    parser.add_argument("age")
    parser.add_argument("occupation")
    args = parser.parse_args()

    for user in users:
        if(name == user["name"]):
            user["age"] = args["age"]
            user["occupation"] = args["occupation"]
            user["prediction"] = args["str(predicted[0][0])"]
            return user, 200
    
    user = {
        "name": name,
        "age": args["age"],
        "occupation": args["occupation"],
        "prediction": args["str(predicted[0][0])"]
    }
    users.append(user)
    return user, 201

def delete(self, name):
    global users
    users = [user for user in users if user["name"] != name]
    return "{} is deleted.".format(name), 200

api.add_resource(User, "/user/string:name")

app.run(debug=True)

### All the error

Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 458, in wrapper resp = resource(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\views.py", line 88, in view return self.dispatch_request(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 573, in dispatch_request resp = meth(*args, **kwargs) File "C:\xampp\htdocs\faceD\app.py", line 61, in post model = load_model('C:/Users/ASUS/Downloads/mse-04-0.0877.h5') File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = deserialize_model(f, custom_objects, compile) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 287, in deserialize_model K.batch_set_value(weight_value_tuples) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 2470, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 929, in run run_metadata_ptr) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1095, in run 'Cannot interpret feed_dict key as Tensor: ' + e.args[0]) TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph. 127.0.0.1 - - [20/May/2019 21:21:32] "POST /user/Nicholas HTTP/1.1" 500 - Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 458, in wrapper resp = resource(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\views.py", line 88, in view return self.dispatch_request(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 573, in dispatch_request resp = meth(*args, **kwargs) File "C:\xampp\htdocs\faceD\app.py", line 70, in post predicted = model.predict(test_x) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1169, in predict steps=steps) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training_arrays.py", line 294, in predict_loop batch_outs = f(ins_batch) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 2715, in call return self.call(inputs) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 2675, in call fetched = self.callable_fn(*array_vals) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1439, in call run_metadata_ptr) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 528, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value dense_1/bias [[{{node dense_1/bias/read}}]] 127.0.0.1 - - [20/May/2019 21:21:33] "POST /user/Nicholas HTTP/1.1" 500 - Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2309, in call return self.wsgi_app(environ, start_response) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2295, in wsgi_app response = self.handle_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1741, in handle_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 269, in error_router return original_handler(e) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 34, in reraise raise value.with_traceback(tb) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functionsrule.endpoint File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init.py", line 458, in wrapper resp = resource(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask\views.py", line 88, in view return self.dispatch_request(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\flask_restful_init_.py", line 573, in dispatch_request resp = meth(*args, **kwargs) File "C:\xampp\htdocs\faceD\app.py", line 61, in post model = load_model('C:/Users/ASUS/Downloads/mse-04-0.0877.h5') File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\saving.py", line 287, in _deserialize_model K.batch_set_value(weight_value_tuples) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 2470, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 929, in run run_metadata_ptr) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1095, in _run 'Cannot interpret feed_dict key as Tensor: ' + e.args[0]) TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph.

tensorflow/tensorflow

Answer questions muddham

@yensan0512 Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

useful!

Related questions

Error occurred when finalizing GeneratorDataset iterator hot 4
The flag 'log_dir' is defined twice. hot 3
Using tensorflow gpu 2.1 with Cuda 10.2 hot 2
tf.strings.split bug hot 2
Cannot run tensorflow GPU 2.0 with cuda 9.2 hot 2
module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell' hot 2
Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. hot 2
compiling c++ code with TFLite library gives error with cstring hot 2
Tensorflow 2.0 error when used via pyinstaller build - ImportError: cannot import name 'pywrap_tensorflow' from 'tensorflow_core.python' hot 2
ModuleNotFoundError: No module named 'tensorflow.contrib' hot 2
TF2.0 AutoGraph issue hot 2
Error loading tensorflow hot 2
ModuleNotFoundError: No module named 'tensorflow.contrib' hot 2
AttributeError: module 'tensorflow' has no attribute 'set_random_seed' hot 2
ImportError: cannot import name 'moving_averages' hot 2
Github User Rank List