English 中文(简体)
无法找到从“拯救儿童”组织中装载的配对功能。
原标题:Could not find matching function to call loaded from the SavedModel

我在编码后写道,它假定装上模型,然后从多国专家名册数据集中预测出一个元件。 在执行之初,该守则进行细微的工作,我得到我所期望的预测,但随后,我突然发现以下错误,我无法确定这是否与<编码>有关。

我的法典:

# importing libraries
import tensorflow as tf  # deep learning library. Tensors are just multi-dimensional arrays
import gzip,sys,pickle # dataset manipulation library

# importing MNIST dataset
f = gzip.open( mnist.pkl.gz ,  rb )
if sys.version_info < (3,):
    data = pickle.load(f)
else:
    data = pickle.load(f, encoding= bytes )
f.close()
(x_train, _), (x_test, _) = data

print("-----------------------dataset ready-----------------------")
# using an expample from x_test / to remove later
# preprocessing
x_test = tf.keras.utils.normalize(x_test, axis=1)  # scales data between 0 and 1

# importing model
new_model = tf.keras.models.load_model( epic_num_reader.model )
print("-----------------------model ready-----------------------")

# getting prediction
predictions = new_model.predict(x_test[0])
import numpy as np
print("-----------------------predection ready-----------------------")
print(np.argmax(predictions))

错误信息:

    -----------------------dataset ready-----------------------
    2019-10-27 00:36:58.767359: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
    -----------------------model ready-----------------------
    Traceback (most recent call last):
      File "c:UserslotfiDesktopDigitsDetectormain1.py", line 24, in <module>
        predictions = new_model.predict(x_test[0])
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining.py", line 909, in predict
        use_multiprocessing=use_multiprocessing)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2.py", line 462, in predict
        steps=steps, callbacks=callbacks, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2.py", line 444, in _model_iteration
        total_epochs=1)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2.py", line 123, in run_one_epoch
        batch_outs = execution_function(iterator)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2_utils.py", line 86, in execution_function
        distributed_function(input_fn))
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 457, in __call__
        result = self._call(*args, **kwds)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 503, in _call
        self._initialize(args, kwds, add_initializers_to=initializer_map)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 408, in _initialize
        *args, **kwds))
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 1848, in _get_concrete_function_internal_garbage_collected
        graph_function, _, _ = self._maybe_define_function(args, kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 2150, in _maybe_define_function
        graph_function = self._create_graph_function(args, kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 2041, in _create_graph_function
        capture_by_value=self._capture_by_value),
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonframeworkfunc_graph.py", line 915, in func_graph_from_py_func
        func_outputs = python_func(*func_args, **func_kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 358, in wrapped_fn
        return weak_wrapped_fn().__wrapped__(*args, **kwds)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2_utils.py", line 73, in distributed_function
        per_replica_function, args=(model, x, y, sample_weights))
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythondistributedistribute_lib.py", line 760, in experimental_run_v2
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythondistributedistribute_lib.py", line 1787, in call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythondistributedistribute_lib.py", line 2132, in _call_for_each_replica
        return fn(*args, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonautographimplapi.py", line 292, in wrapper
        return func(*args, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2_utils.py", line 162, in _predict_on_batch
        return predict_on_batch(model, x)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasengine	raining_v2_utils.py", line 370, in predict_on_batch
        return model(inputs)  # pylint: disable=not-callable
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasenginease_layer.py", line 847, in __call__
        outputs = call_fn(cast_inputs, *args, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasenginesequential.py", line 270, in call
        outputs = layer(inputs, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerasenginease_layer.py", line 847, in __call__
        outputs = call_fn(cast_inputs, *args, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonkerassavingsaved_modelutils.py", line 57, in return_outputs_and_add_losses
        outputs, losses = fn(inputs, *args, **kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 457, in __call__
        result = self._call(*args, **kwds)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 494, in _call
        results = self._stateful_fn(*args, **kwds)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 1822, in __call__
        graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 2150, in _maybe_define_function
        graph_function = self._create_graph_function(args, kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerfunction.py", line 2041, in _create_graph_function
        capture_by_value=self._capture_by_value),
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonframeworkfunc_graph.py", line 915, in func_graph_from_py_func
        func_outputs = python_func(*func_args, **func_kwargs)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythoneagerdef_function.py", line 358, in wrapped_fn
        return weak_wrapped_fn().__wrapped__(*args, **kwds)
      File "C:UserslotfiAnaconda3envs	flibsite-packages	ensorflow_corepythonsaved_modelfunction_deserialization.py", line 262, in restored_function_body
        "

".join(signature_descriptions)))

3. 错误信息继续:

    ValueError: Could not find matching function to call loaded from the SavedModel. Got:
      Positional arguments (1 total):
        * Tensor("inputs:0", shape=(None, 28), dtype=float32)
      Keyword arguments: {}
    Expected these arguments to match one of the following 1 option(s):
    Option 1:
      Positional arguments (1 total):
        * TensorSpec(shape=(None, 28, 28), dtype=tf.float32, name= inputs )
      Keyword arguments: {}

问题回答

注:我认为你的问题是《规则范本》的一部分。 在该部分,你使用了x_test[0],这与预先培训的模式阵容不相配。 你们必须使用X-测试而不是X-测试[0]。 “entergraph

   #Use This Code TO Solve Your Problem
    
    
    import tensorflow as tf  # deep learning library. Tensors are just multi-dimensional arrays
    
    mnist = tf.keras.datasets.mnist  # mnist is a dataset of 28x28 images of handwritten digits and their labels
    (x_train, y_train),(x_test, y_test) = mnist.load_data()  # unpacks images to x_train/x_test and labels to y_train/y_test
    
    x_train = tf.keras.utils.normalize(x_train, axis=1)  # scales data between 0 and 1
    x_test = tf.keras.utils.normalize(x_test, axis=1)  # scales data between 0 and 1
    
    model = tf.keras.models.Sequential()  # a basic feed-forward model
    model.add(tf.keras.layers.Flatten())  # takes our 28x28 and makes it 1x784
    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))  # a simple fully-connected layer, 128 units, relu activation
    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))  # a simple fully-connected layer, 128 units, relu activation
    model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))  # our output layer. 10 units for 10 classes. Softmax for probability distribution
    
    model.compile(optimizer= adam ,  # Good default optimizer to start with
                  loss= sparse_categorical_crossentropy ,  # how will we calculate our "error." Neural network aims to minimize loss.
                  metrics=[ accuracy ])  # what to track
    
    model.fit(x_train, y_train, epochs=3)  # train the model
    
    val_loss, val_acc = model.evaluate(x_test, y_test)  # evaluate the out of sample data with model
    print(val_loss)  # model s loss (error)
    print(val_acc)  # model s accuracy

--------------------------Save Model----------------------------------------

model.save( epic_num_reader.model ) # save the model

--------------------------Load Model----------------------------------------

new_model = tf.keras.models.load_model( epic_num_reader.model ) # Load the model

--------------------------Predict Model-------------------------------------

predictions = new_model.predict(x_test)
print(predictions)

--------------------------visualize Prediction------------------------------

plt.imshow(x_test[0],cmap=plt.cm.binary)
plt.show()

-------------------------- Validated Prediction-----------------------------

import numpy as np

print(np.argmax(predictions[0]))

Had the same issue. Try:

    pip install tf-nightly

Solution is from here: https://github.com/tensorflow/tensorflow/issues/35446 - comment from oanush.

But this may break calling of tensorboards if you have one. Step by step solution for this is below:

    pip uninstall tensorflow
    pip uninstall tensorboard
    pip install -q tf-nightly
    pip install --ignore-installed tf-nightly

Got if from here: https://github.com/tensorflow/tensor板/issues/22<26/a> - 从2019年6月29日,毫米号发表评论。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签