Python ';返回';是否超出功能误差keras预测值
我正在尝试从URL获取图像。在另一个文件上显示输出。我正在使用keras和tensorflow运行代码,但返回函数不起作用。如何解决这个问题?我从另一个文件中得到了结果Python ';返回';是否超出功能误差keras预测值,python,tensorflow,keras,deep-learning,caffe,Python,Tensorflow,Keras,Deep Learning,Caffe,我正在尝试从URL获取图像。在另一个文件上显示输出。我正在使用keras和tensorflow运行代码,但返回函数不起作用。如何解决这个问题?我从另一个文件中得到了结果 def get_score(file, model=weapon_model): tmp_filename = "" if file.find('http') != -1: random_text = "".join([random.choice(string.ascii_letters
def get_score(file, model=weapon_model):
tmp_filename = ""
if file.find('http') != -1:
random_text = "".join([random.choice(string.ascii_letters[:26]) for i in range(15)])
tmp_filename = "res/" + random_text + "out.jpg"
if not os.path.isdir('res/'):
os.mkdir("res/")
URL = file
c = urllib3.PoolManager()
with c.request('GET', URL, preload_content=False) as resp, open(tmp_filename, "wb") as out_file:
shutil.copyfileobj(resp, out_file)
resp.release_conn()
file = tmp_filename
m,n = 50,50
im = Image.open(file);
imrs = im.resize((m,n))
imrs=img_to_array(imrs)/255;
imrs=imrs.transpose(2,0,1);
imrs=imrs.reshape(3,m,n);
x=[];
x.append(imrs);
x=np.array(x);
predictions = weapon_model.predict(x)[:,1]
#predictions = weapon_model.predict(x)
print (predictions)
print ("Weapon score: ", predictions[1])
return predictions
请尝试下面的缩进代码
def get_score(file, model=weapon_model):
tmp_filename = ""
if file.find('http') != -1:
random_text = "".join([random.choice(string.ascii_letters[:26]) for i in range(15)])
tmp_filename = "res/" + random_text + "out.jpg"
if not os.path.isdir('res/'):
os.mkdir("res/")
URL = file
c = urllib3.PoolManager()
with c.request('GET', URL, preload_content=False) as resp, open(tmp_filename, "wb") as out_file:
shutil.copyfileobj(resp, out_file)
resp.release_conn()
file = tmp_filename
m,n = 50,50
im = Image.open(file);
imrs = im.resize((m,n))
imrs=img_to_array(imrs)/255;
imrs=imrs.transpose(2,0,1);
imrs=imrs.reshape(3,m,n);
x=[];
x.append(imrs);
x=np.array(x);
predictions = weapon_model.predict(x)[:,1]
#predictions = weapon_model.predict(x)
print (predictions)
print ("Weapon score: ", predictions[1])
return predictions
您的代码中没有
return
。它的缩进似乎也不正确。我使用的返回函数itz不工作……这与keras或任何其他库无关。你的缩进搞乱了,这是Python的一个关键特性,因为代码块上没有大括号。我的错误…你在上面的代码中做了什么更改?我没有修改任何东西,我做了缩进。它已成功编译,但无法调试,因为不知道什么是输入参数。\u model还有一件事您的输入参数是“model”,您在代码中使用过它吗?预测=武器模型。预测(x)[:,1]。你想用“模型”代替“武器模型”吗?