Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的keras.utils.Sequence返回3个数组,我可以';不要把它放在model.fit里_Python_Tensorflow_Keras - Fatal编程技术网

Python 我的keras.utils.Sequence返回3个数组,我可以';不要把它放在model.fit里

Python 我的keras.utils.Sequence返回3个数组,我可以';不要把它放在model.fit里,python,tensorflow,keras,Python,Tensorflow,Keras,正如您在标题my keras.utils.Sequence return 3数组中所读到的那样。 如何将model.fit(..)与keras.utils.Sequence对象的3个输出一起使用 def __getitem__(self, index): 'Generate one batch of data' # Generate indexes of the batch indexes = self.indexes[index*self

正如您在标题my keras.utils.Sequence return 3数组中所读到的那样。 如何将model.fit(..)与keras.utils.Sequence对象的3个输出一起使用

    def __getitem__(self, index):
        'Generate one batch of data'
        # Generate indexes of the batch
        indexes = self.indexes[index*self.batch_size:(index+1)*self.batch_size]

        # Find list of IDs
        list_IDs_temp = [self.list_IDs[k] for k in indexes]

        # Generate data
        X,Xt,y= self.__data_generation(list_IDs_temp)

        return X,Xt,y

X是我的原始图像,Xt是变换后的图像,y是标签。 我想编译下面的代码:

model_englobe.fit(generated_image_train,batch_size=1,epochs=2)
我的模型采用两个输入X我的原始图像Xt。
生成的\u图像\u列[i]
是批次号i
generated\u image\u train[i][0]
i在这里选择所有原始图像,
generated\u image\u train[i][1]
i在这里选择所有转换后的图像,
generated\u image\u train[i][2]
i在这里选择所有标签

显示错误:

    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function  *
        return step_function(self, iterator)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
        return fn(*args, **kwargs)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step  **
        outputs = model.train_step(data)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:754 train_step
        y_pred = self(x, training=True)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__
        input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/input_spec.py:207 assert_input_compatibility
        ' input tensors. Inputs received: ' + str(inputs))

    ValueError: Layer model expects 2 input(s), but it received 1 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None, None, None) dtype=float32>]
/usr/local/lib/python3.7/dist包/tensorflow/python/keras/engine/training.py:805 train\u函数*
返回步骤_函数(self、迭代器)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_函数**
输出=模型。分配策略。运行(运行步骤,参数=(数据,)
/usr/local/lib/python3.7/dist包/tensorflow/python/distribute/distribute_lib.py:1259运行
返回self.\u扩展。为每个\u副本调用\u(fn,args=args,kwargs=kwargs)
/usr/local/lib/python3.7/dist包/tensorflow/python/distribute/distribute_lib.py:2730为每个复制副本调用
返回自我。为每个副本(fn、ARG、kwargs)调用
/usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute\u-lib.py:3417\u为每个副本调用\u
返回fn(*args,**kwargs)
/usr/local/lib/python3.7/dist包/tensorflow/python/keras/engine/training.py:788运行步骤**
输出=型号列车步进(数据)
/usr/local/lib/python3.7/dist包/tensorflow/python/keras/engine/training.py:754 train\u步骤
y_pred=self(x,training=True)
/usr/local/lib/python3.7/dist包/tensorflow/python/keras/engine/base\u layer.py:998\u调用__
输入\规格.断言\输入\兼容性(self.input \规格,输入,self.name)
/usr/local/lib/python3.7/dist包/tensorflow/python/keras/engine/input\u spec.py:207断言\u输入\u兼容性
'输入张量。收到的输入:'+str(输入))
ValueError:层模型需要2个输入,但收到1个输入张量。收到的投入:[]

非常感谢

如果生成器返回3个变量,那么keras假设您返回的是X、y和样本权重。要传递两个输入,必须以如下列表的形式返回X和Xt:

def\uuuu getitem\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
“生成一批数据”
#生成批处理的索引
索引=自索引[索引*自批大小:(索引+1)*自批大小]
#查找ID列表
list_id_temp=[索引中k的self.list_id[k]
#生成数据
十、 Xt,y=自身数据生成(列表ID温度)
返回[X,Xt],y

有关更多信息,请检查
fit
函数中的
x
参数。

谢谢,但是我有一个错误:ValueError:in user code:/usr/local/lib/python3.7/dist packages/tensorflow/python/keras/engine/training.py:805 train_函数*return step_函数(self,iterator):17 call*self.total[i,j].assign(tensor_sub)/usr/local/lib/python3.7/dist packages/tensorflow/python/ops/array_ops.py:1229 assign**raise ValueError(“切片赋值仅支持变量”)ValueError:切片赋值仅支持变量。你知道这是什么意思吗?也许我弄错了,你能试着返回一个列表而不是元组吗?像[X,Xt]。。我已经编辑了我的答案。由于元组不支持切片,这就是它抛出错误的原因。我有同样的错误:ValueError:切片赋值仅支持变量我认为这是我的层,根据这篇文章:我可以写:tensor_sub=tf.math.reduce_sum(tf.math.abs(tf.subtract)(in1[0,I,j,:],in2[0,:]))如果in1,in2是张量OK非常感谢