ValueError:Tensor(“ Placeholder:0”,shape =(),dtype = float32)必须与Tensor(“ total:0”,shape =(),dtype = resource)来自同一张图

时间:2019-02-28 22:15:03

标签: python-3.x tensorflow flask

我建立了一个三层神经网络,根据其内容预测一列的正确名称。该模型在tensorflow 1.12上运行良好;它甚至现在已经部署并投入生产。

但是,当我们尝试使用tensorflow 1.13运行相同的服务时,它因以下错误而中断。

  

127.0.0.1--[28 / Feb / 2019 16:28:15]“ [1m [35mPOST / 999 / qqq / upload_to_column_check HTTP / 1.1 [0m] 500-追溯(大部分   最近通话结束):文件   “ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,第1997行,   在致电中       返回self.wsgi_app(环境,start_response)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,行1985,   在wsgi_app中       响应= self.handle_exception(e)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,第1540行,   在handle_exception中       重新提升(exc_type,exc_value,tb)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask_compat.py”,行   33,在加薪       提高价值文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,行1982,   在wsgi_app中       响应= self.full_dispatch_request()文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,行1614,   在full_dispatch_request中       rv = self.handle_user_exception(e)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,第1517行,   在handle_user_exception中       重新提升(exc_type,exc_value,tb)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask_compat.py”,行   33,在加薪       提高价值文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,行1612,   在full_dispatch_request中       rv = self.dispatch_request()文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ flask \ app.py”,行1598,   在dispatch_request中       返回self.view_functionsrule.endpoint文件“ C:\ Users \ Matt   Casey \ iqm \ iqmpolisegments-datarecievers-columnnames \ api_service.py”,   第231行,在upload_then_columns中       name_dict,conf = cp.predict_based_on_header_and_list(ColName,ColVals)文件“ C:\ Users \ Matt   Casey \ iqm \ iqmpolisegments-datarecievers-columnnames \ header_service_core.py”,   第299行,位于predict_based_on_header_and_list中       lpreds = self.predict_based_on_list(initial,arr_only = True)文件“ C:\ Users \ Matt   Casey \ iqm \ iqmpolisegments-datarecievers-columnnames \ header_service_core.py”,   第237行,位于predict_based_on_list中       preds = self.classifier.predict(矢量化)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ keras \ engine \ training.py”,   行1113,在预测中       自我,x,batch_size =批量大小,详细=详细,步骤=步骤)文件   “ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ keras \ engine \ training_arrays.py”,   第251行,在model_iteration中       model.reset_metrics()文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ keras \ engine \ training.py”,   第1119行,在reset_metrics中       m.reset_states()文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ keras \ metrics.py”,   第460行,处于reset_states       K.set_value(v,0)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ keras \ backend.py”,   set_value中的第2844行       Assign_op = x.assign(assign_placeholder)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ ops \ resource_variable_ops.py”,   分配中的第917行       self.handle,value_tensor,name = name)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ ops \ gen_resource_variable_ops.py”,   第186行,在assign_variable_op中       “ AssignVariableOp”,资源=资源,值=值,名称=名称)文件   “ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ framework \ op_def_library.py”,   第350行,在_apply_op_helper中       g = ops._get_graph_from_inputs(_Flatten(keywords.values()))文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ framework \ ops.py”,   _get_graph_from_inputs中的第5713行       _assert_same_graph(original_graph_element,graph_element)文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ framework \ ops.py”,   _assert_same_graph中的第5649行       original_item))ValueError:Tensor(“ Placeholder:0”,shape =(),dtype = float32)必须与Tensor(“ total:0”,来自同一图形,   shape =(),dtype = resource)。

我无法理解这一点。因此,我将对象拉进Jupyter笔记本进行故障排除。除非,当我这样做时,错误消失了,并且可以正常工作。

以下应为相关代码:

def predict_based_on_list(self, initial, arr_only = False):
    """
    Initial:
        str in list form, values separated by '|'
        OR a list of strings. The strings should all be values from the
        same column of a spreadsheet

    returns:
        np.array, the output of the neural network with shape (1, len(headers)).
        Each entry in the array represents affinity for a particular column
        the higher the value, the closer the affinity.
    """
    conf_array = np.zeros((1, len(self.headers)))
    if type(initial) == str:
        vals = initial.split('|')
        print('in split', vals)
    else:
        vals = initial
        print('in = initial', vals)
    rows = len(vals)
    vectorized = [self.convert_val_to_metadata(val) for val in vals]
    vectorized = pd.DataFrame(vectorized)
    vectorized.fillna(0, inplace=True)

    vectorized = np.array(vectorized, dtype='float64')

    preds = self.classifier.predict(vectorized)

    avgs = preds.sum(axis=0) / len(vals)

    return avgs

如果您有任何出色的想法,我很想听听他们的想法。我感到困惑。

0 个答案:

没有答案