Python model.predict为attr'给出了Tensorflow误差不一致的值;T';DT_INT16 vs.DT_FLOAT,同时使用Op name=strideslice构建NodeDef

Python model.predict为attr'给出了Tensorflow误差不一致的值;T';DT_INT16 vs.DT_FLOAT,同时使用Op name=strideslice构建NodeDef,python,tensorflow,tensorflow2.0,Python,Tensorflow,Tensorflow2.0,此predict()行抛出一个错误,与切片操作中的数字类型有关。这很奇怪,因为x是在这个模型上传递给fit()的同一个x变量,它工作得很好 print(f"x type: {x.dtype}") pred = model.predict(x[:4], verbose=1) x type: int16 4/1 [=============================================================================================

此predict()行抛出一个错误,与切片操作中的数字类型有关。这很奇怪,因为x是在这个模型上传递给fit()的同一个x变量,它工作得很好

print(f"x type: {x.dtype}")
pred = model.predict(x[:4], verbose=1)

x type: int16
4/1 [========================================================================================================================] - 0s 9ms/sample

---------------------------------------------------------------------------

InvalidArgumentError                      Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py in _create_c_op(graph, node_def, inputs, control_inputs)
   1609   try:
-> 1610     c_op = c_api.TF_FinishOperation(op_desc)
   1611   except errors.InvalidArgumentError as e:

InvalidArgumentError: Inconsistent values for attr 'T' DT_INT16 vs. DT_FLOAT while building NodeDef 'MultiLatentFactorEmbeddings/tf_op_layer_strided_slice_9/strided_slice_9' using Op<name=StridedSlice; signature=input:T, begin:Index, end:Index, strides:Index -> output:T; attr=T:type; attr=Index:type,allowed=[DT_INT32, DT_INT64]; attr=begin_mask:int,default=0; attr=end_mask:int,default=0; attr=ellipsis_mask:int,default=0; attr=new_axis_mask:int,default=0; attr=shrink_axis_mask:int,default=0>

你找到什么了吗?有类似问题:)
pred = model.predict(x[:4].astype('float32'), verbose=1)
print(pred)
print(len(pred))

[array([3.194112 , 5.085145 , 4.006051 , 2.2034621], dtype=float32), array([3.3063915, 4.306922 , 3.6413522, 3.8829203], dtype=float32), array([3.7104087, 4.3858795, 4.01692  , 1.898252 ], dtype=float32), array([3.203589 , 5.172986 , 3.026092 , 3.6376379], dtype=float32), array([3.7957292, 4.461877 , 4.000422 , 1.9542396], dtype=float32), array([3.7817342, 3.8966684, 3.624828 , 3.4967134], dtype=float32), array([2.8993552, 4.552232 , 3.719839 , 3.7932575], dtype=float32), array([3.7712648, 4.679196 , 4.0168233, 2.164474 ], dtype=float32), array([3.790591 , 4.019288 , 3.7273784, 3.483149 ], dtype=float32), array([3.913386 , 4.172969 , 3.750421 , 3.4700112], dtype=float32), array([3.0101657, 4.1036396, 3.6925082, 3.5632277], dtype=float32), array([3.6850617, 4.036703 , 3.8202734, 2.1823971], dtype=float32), array([3.624076 , 3.5624738, 3.5624738, 3.3048732], dtype=float32), array([3.714932 , 3.977636 , 3.7739916, 3.3787155], dtype=float32), array([3.820767 , 3.6931853, 3.545939 , 3.5191858], dtype=float32), array([3.0579495, 4.414914 , 3.6709092, 3.6772912], dtype=float32), array([3.6208365, 4.373149 , 3.831347 , 1.8817322], dtype=float32), array([3.6779041, 3.6779041, 3.5459585, 3.5459566], dtype=float32), array([3.7410715, 4.0781364, 3.1003942, 3.3844185], dtype=float32), array([3.8562837, 3.9519095, 3.542011 , 3.4095852], dtype=float32), array([3.580582, 3.436636, 3.448217, 3.406483], dtype=float32), array([3.3215585, 3.9647496, 3.6743877, 3.704747 ], dtype=float32), array([3.445878 , 4.118546 , 3.775422 , 1.7540922], dtype=float32), array([3.7162511, 3.480415 , 3.494589 , 3.4945881], dtype=float32), array([3.684245 , 3.5771437, 3.5121186, 3.276648 ], dtype=float32), array([3.773697 , 3.779047 , 3.4952793, 3.2622762], dtype=float32), array([3.4537246, 3.196083 , 3.7369132, 3.5790577], dtype=float32), array([3.6998277, 3.393783 , 3.3812099, 3.3812099], dtype=float32), array([3.021385, 4.572421, 3.815578, 4.226384], dtype=float32), array([3.2178297, 4.916973 , 4.009197 , 2.3856788], dtype=float32), array([3.4066412, 4.454532 , 3.772382 , 3.7187898], dtype=float32), array([3.393184 , 4.7299614, 2.8204403, 3.6678872], dtype=float32), array([3.3476796, 4.736937 , 3.7204177, 3.881307 ], dtype=float32), array([3.1741242, 4.4121904, 3.874723 , 3.800518 ], dtype=float32), array([3.36439  , 4.2329254, 3.658211 , 3.6337106], dtype=float32), array([3.6154706, 4.244628 , 3.7012188, 3.5705385], dtype=float32), array([3.0540926, 4.4776115, 3.566447 , 3.4938762], dtype=float32), array([3.7251701, 4.438184 , 3.9370265, 1.6576142], dtype=float32), array([3.6057272, 3.737263 , 3.6411624, 3.4524887], dtype=float32), array([3.6991765, 4.28243  , 4.1980386, 3.2413287], dtype=float32), array([3.7255487, 4.0255885, 3.6522188, 3.2179668], dtype=float32), array([3.5961165, 3.4442449, 3.4905138, 3.110715 ], dtype=float32), array([3.525294 , 3.7369845, 3.4212286, 3.2812388], dtype=float32), array([3.3343515, 3.4638062, 3.418049 , 3.2168102], dtype=float32), array([3.0981493, 4.3047767, 3.5595715, 3.4125452], dtype=float32)]
45