- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 keras fune-tuning 来开发图像分类应用程序。我将该应用程序部署到 Web 服务器,图像分类成功。
但是,当同时从两台或多台计算机使用该应用程序时,会出现以下错误消息并且该应用程序无法运行。
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 3, 64), dtype=float32) is not an element of this graph.
这是我的图像分类代码。
img_height, img_width = 224, 224
channels = 3
input_tensor = Input(shape=(img_height, img_width, channels))
vgg19 = VGG19(include_top=False, weights='imagenet', input_tensor=input_tensor)
fc = Sequential()
fc.add(Flatten(input_shape=vgg19.output_shape[1:]))
fc.add(Dense(256, activation='relu'))
fc.add(Dropout(0.5))
fc.add(Dense(3, activation='softmax'))
model = Model(inputs=vgg19.input, outputs=fc(vgg19.output))
model.load_weights({h5_file_path})
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
img = image.load_img({image_file_path}, target_size=(img_height, img_width))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = x / 255.0
pred = model.predict(x)[0]
如何同时在多台计算机上运行此应用程序?
感谢您阅读这篇文章。
最佳答案
我发现有几种解决方法,具体取决于不同的上下文:
使用 clear_session()
函数:
from keras import backend as K
然后在预测所有数据后,在函数的开头或结尾执行以下操作:
K.clear_session()
调用_make_predict_function()
:
加载经过训练的模型调用后:
model._make_predict_function()
参见 explanation
禁用线程:
如果您正在运行 django 服务器,请使用此命令:
python manage.py runserver --nothreading
对于 flask 使用这个:
flask run --without-threads
如果以上解决方案均无效,请检查这些链接 keras issue#6462 , keras issue#2397
关于python - 凯拉斯, tensorflow : "TypeError: Cannot interpret feed_dict key as Tensor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51588186/
我试图将迁移学习应用于 InceptionV3。这是我的代码: inception_model = InceptionV3(weights='imagenet',include_top=False)
我正在尝试展示 GAN 网络在某些指定时期的结果。打印当前结果的功能以前与 TF 一起使用。我需要换成 pytorch。 def show_result(G_net, z_, num_epoch, s
我对孪生神经网络还很陌生,最近发现了 this example和 Colab notebook . 运行代码时出现以下错误: IndexError: invalid index of a 0-dim
我正在尝试使用在此 PR 中添加的“高级”、numpy 样式的切片,但是我遇到了 same issue as the user here : ValueError: Shape must be ran
我想在 TensorFlow 中做类似这段 Numpy 代码的事情: a = np.zeros([5, 2]) idx = np.random.randint(0, 2, (5,)) row_idx
我有以下特征张量: Eigen::Tensor m(3,10,10); 我想访问第一个矩阵。在 numpy 中我会这样做 m(0,:,:) 我如何在 Eigen 中做到这一点 最佳答案 您可以使用 .
1、问题 模型训练完后进行测试,报错 RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU
我正在对 TFRecords 进行配对,它为我提供了一个标签作为数值。但是我需要在读取原始记录时将此值转换为分类向量。我怎样才能做到这一点。这是读取原型(prototype)记录的代码片段: def
我正在对 TFRecords 进行配对,它为我提供了一个标签作为数值。但是我需要在读取原始记录时将此值转换为分类向量。我怎样才能做到这一点。这是读取原型(prototype)记录的代码片段: def
我应该如何从 Eigen::Tensor 创建一个 tensorflow::Tensor?我可以一个接一个地复制元素,但我希望有更好的方法。 最佳答案 没有公共(public) api 可以在不复制数
我正在尝试使用 Tensorflow(版本 0.9.0)以与 beginner's tutorial 非常相似的方式训练一个简单的二元逻辑回归分类器。并且在拟合模型时遇到以下错误: ValueErro
从 0.4.0 版本开始,可以使用 torch.tensor 和 torch.Tensor 有什么区别?提供这两个非常相似且令人困惑的替代方案的原因是什么? 最佳答案 在 PyTorch 中,torc
PyTorch0.4中,.data 仍保留,但建议使用 .detach(), 区别在于 .data 返回和 x 的相同数据 tensor, 但不会加入到x的计算历史里,且require s_grad
我有一个参差不齐的张量,在尝试创建模型并使用 model.fit() 时,出现错误:TypeError: Failed to convert object of type to Tensor. Co
我必须用生成器和判别器训练一个 GAN 网络。我的发电机网络如下。 def Generator(image_shape=(512,512,3): inputs = Input(image_shap
我正在使用 Flask 运行 Web 服务器,当我尝试使用 vgg16 时出现错误,vgg16 是 keras 的预训练 VGG16 模型的全局变量。我不知道为什么会出现这个错误,也不知道它是否与 T
我正在使用 keras 的预训练模型,并且在调用 ResNet50(weights='imagenet') 时出现错误。 我在 flask 服务器中有以下代码: def getVGG16Predict
执行以下代码时出现以下错误。 rnn.rnn() 返回张量列表。错误在 convert_to_tensor 行。 TypeError: List of Tensors when single Tens
我有一个fruit_train_net.py 文件,其中包含以下代码 import tensorflow as tf import numpy as np import time import os
我们可以使用 torch.Tensor([1., 2.], device='cuda') 在 GPU 上分配张量.使用这种方式而不是torch.cuda.Tensor([1., 2.])有什么不同吗?
我是一名优秀的程序员,十分优秀!