Python 3.x AssertionError:无法计算输出张量(“output1/LeakyRelu:0”,shape=(无,1),dtype=float32)
您好,我尝试基于keras中的fit_generator()函数建立一些模型。 我的模型分为多变量模型,它有多个输出。 有一次我使用了这个函数,得到了如下所示的错误 -->306 hist=model.fit_生成器(数据生成器([X_tr_列表[i]用于范围内的i(len(X_tr_列表))),[Y_tr[i]用于范围内的i(Y_tr.shape[0]),32),epoch=1000,verbose=1,回调=[checkpoint,es,best],验证数据=(数据生成器([X_te_列表[X]用于范围内的X(len(len(X_te_列表)),[Y_te[i]用于范围内的i(Y_te.shape]),32]),32) 307图=plt.图() 308 12帧 /包装器中的usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py(*args,**kwargs) 971例外情况为e:#pylint:disable=broad except 972如果hasattr(e,“AGU错误元数据”): -->973将e.ag\u错误\u元数据引发到\u异常(e) 974其他: 975提高 断言错误:在用户代码中:Python 3.x AssertionError:无法计算输出张量(“output1/LeakyRelu:0”,shape=(无,1),dtype=float32),python-3.x,keras,batch-processing,hdf5,multivariate-partition,Python 3.x,Keras,Batch Processing,Hdf5,Multivariate Partition,您好,我尝试基于keras中的fit_generator()函数建立一些模型。 我的模型分为多变量模型,它有多个输出。 有一次我使用了这个函数,得到了如下所示的错误 -->306 hist=model.fit_生成器(数据生成器([X_tr_列表[i]用于范围内的i(len(X_tr_列表))),[Y_tr[i]用于范围内的i(Y_tr.shape[0]),32),epoch=1000,verbose=1,回调=[checkpoint,es,best],验证数据=(数据生成器([X_te_列表[
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:806 train_function *
return step_function(self, iterator)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:796 step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:1211 run
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2585 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2945 _call_for_each_replica
return fn(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:789 run_step **
outputs = model.train_step(data)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:747 train_step
y_pred = self(x, training=True)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py:985 __call__
outputs = call_fn(inputs, *args, **kwargs)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/functional.py:386 call
inputs, training=training, mask=mask)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/functional.py:517 _run_internal_graph
assert x_id in tensor_dict, 'Could not compute output ' + str(x)
AssertionError: Could not compute output Tensor("output1/LeakyRelu:0", shape=(None, 1), dtype=float32)
有关更多信息,输入数据的形状写在下面
X_tr(1440043914,4)
克苏特(1440018821,4)
尤特(718821)
Y_tr(743914)
有了这些,当我运行模型时,我得到了这个错误,我的模型中使用的代码如下所示
#Generator
def datagenerator(data_input_1, data_input_2, batchsize, mode="train"):
while True:
start = 0
end = batchsize
data_input_1 = np.array(data_input_1)
data_input_2 = np.array(data_input_2)
while start < len(data_input_1[1]):
# load your images from numpy arrays or read from directory
x = data_input_1[:,start:end,:]
y = data_input_2[:,start:end]
yield x, y
print(np.shape(x), printshape(y))
start += batchsize
end += batchsize
print("x",np.shape(x))
print("y",np.shape(y))
return x, y
hist = model.fit_generator(datagenerator([X_tr_list[i] for i in range(len(X_tr_list))], [Y_tr[i] for i in range(Y_tr.shape[0])], 32), epochs=1000, verbose=1, callbacks=[checkpoint, es, best], validation_data=(datagenerator([X_te_list[x] for x in range(len(X_te_list))], [Y_te[i] for i in range(Y_te.shape[0])], 32)))
#生成器
def数据发生器(数据输入1、数据输入2、批次大小、模式=“列车”):
尽管如此:
开始=0
结束=批量大小
数据输入1=np.数组(数据输入1)
data\u input\u 2=np.数组(data\u input\u 2)
启动时
你能帮我吗?
谢谢