多损失模型使凯拉斯早期停止失败

时间:2017-06-15 22:17:57

标签: neural-network keras

我已经在几个模型上成功使用了Keras早期停止功能,但如果我尝试在具有两个输出的模型上使用它并且每个模型都有一个单独的损耗指标,那么如果失败: vae1.compile(optimizer =&#39 ; adam',loss = {' out_1':self.vae_loss,' out_2':' mse'})

当不使用早期停止时,模型适合并成功执行。但是,下面的代码会产生以下结果: ValueError:无法为Tensor u&#39; x_2:0&#39;提供形状值(8,1),其形状为&#39;(10,1)< / EM>&#39;:

  

early_stopping = EarlyStopping(监听=&#39; val_loss&#39;,耐心= 5)

     

model.fit({&#39; x_1&#39;:self.X_train,&#39; x_2&#39;:self.Y_train},{&#39; out_1&#39;:self。 X_train,&#39; out_2&#39;:self.Y_train},               shuffle = True,epochs = self.argsD [&#39; number_epoch&#39;],batch_size = self.argsD [&#39; batch_size&#39;],               回调[model_checkpoint,early_stopping],validation_split = 0.2,verbose = self.argsD [&#39; verbose_fit&#39;])

这引出了我的问题:

  1. Keras早期停止支持多部分损失功能吗?
  2. 如果是,我的代码需要进行哪些更改?
  3. 感谢。

    michetonu:

    当我尝试使用以下方法拟合模型时,抛出错误。错误消息在方法代码下面。

    非常感谢,如果您需要更多信息,请告诉我。

      

    方法

         
        

    def train_es(self):             model_checkpoint = ModelCheckpoint(&#39; model.h5&#39;,monitor =&#39; loss&#39;,save_best_only = True)             model = self.model_vae()             model.summary()             early_stopping = EarlyStopping(监视器=&#39; val_loss&#39;,耐心= 5)             #model.fit(x,y,validation_split = 0.2,callbacks = [early_stopping])
         model.fit({&#39; x_1&#39;:self.X_train,&#39; x_2&#39;:self.Y_train},{&#39; out_1&#39;:self.X_train,&#39;输出2插孔&#39;:self.Y_train}                 shuffle = True,epochs = self.argsD [&#39; number_epoch&#39;],batch_size = self.argsD [&#39; batch_size&#39;],                 callbacks = [model_checkpoint,early_stopping],validation_split = 0.2,verbose = self.argsD [&#39; verbose_fit&#39;])

      
         

    错误消息

         
        

    文件&#34; /Volumes/WiltBUP/@Analysis-Stats/@NN_CategoricalVariables/@AV/VAE/vae_cat_class_combs_4_S1.py" ;,第275行,在       主要()     文件&#34; /Volumes/WiltBUP/@Analysis-Stats/@NN_CategoricalVariables/@AV/VAE/vae_cat_class_combs_4_S1.py" ;,第271行,主要内容       submitCombs_2(dataPlus,combBase,evalNotice2,args,combKeys,combVals)     文件&#34; /Volumes/WiltBUP/@Analysis-Stats/@NN_CategoricalVariables/@AV/VAE/vae_cat_class_combs_4_S1.py" ;,第244行,在submitCombs_2中       p0,p1,p2 = VAE.main(combBase,comb,data,args)     文件&#34; /Volumes/WiltBUP/@Analysis-Stats/@NN_CategoricalVariables/@AV/VAE/vae_cat_class_HPOpt4.py" ;,第242行,主要内容       vae.train_es()     文件&#34; /Volumes/WiltBUP/@Analysis-Stats/@NN_CategoricalVariables/@AV/VAE/vae_cat_class_HPOpt4.py" ;,第117行,在train_es       callbacks = [model_checkpoint,early_stopping],validation_split = 0.2,verbose = self.argsD [&#39; verbose_fit&#39;])     文件&#34; /usr/local/lib/python2.7/site-packages/keras/engine/training.py" ;,第1498行,in fit       initial_epoch = initial_epoch)     文件&#34; /usr/local/lib/python2.7/site-packages/keras/engine/training.py",第1152行,在_fit_loop中       outs = f(ins_batch)     文件&#34; /usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py",第2229行,致电       feed_dict = feed_dict)     文件&#34; /usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py" ;,第767行,在运行中       run_metadata_ptr)     文件&#34; /usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py" ;,第944行,在_run中       %(np_val.shape,subfeed_t.name,str(subfeed_t.get_shape())))

      

    ValueError:无法为Tensor u&#39; x_2:0&#39;提供形状值(8,1),其形状为&#39;(10,1)&#39;

0 个答案:

没有答案