gpt4 book ai didi

python - tensorflow.python.framework.errors_impl.InvalidArgumentError

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:44 26 4
gpt4 key购买 nike

在终端窗口上,当图像传递到 tensorflow 以进行图像对象识别时,它运行良好:

python run.py http://image_url.jpg

但是,对于包含 imageURL 流的 JSON 数据,它失败并出现以下主要错误:

InvalidArgumentError: Invalid JPEG data or crop window, data size 15022
[[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_DecodeJpeg/contents_0_0)]]
Caused by op u'DecodeJpeg'

遇到另一个错误:

ValueError:GraphDef 不能大于 2GB。

下面是我的 tensorflow 源代码作为一个函数(它再次使用作为参数传递的单个 ImageUrl 运行):

import tensorflow as tf
import sys
import os
import urllib2

def tensorflow_pred(imageUrl):

#suppress TF log-info messages - remove to display TF logs
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

response = urllib2.urlopen(imageUrl)

image_data = response.read()

# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("./retrained_labels.txt")]

# Unpersists graph from file
with tf.gfile.FastGFile("./retrained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')

with tf.Session() as sess:
# Feed the image_data as input to the graph and get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')

predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})

# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]

for node_id in top_k:
classification = label_lines[node_id]
score = predictions[0][node_id]
if (score >=0.5):
return ('%s (score = %.5f)' % (classification, score))

最佳答案

我创建了一个workaround对于这个问题。

关于python - tensorflow.python.framework.errors_impl.InvalidArgumentError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49414902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com