Keras。 ValueError:关闭文件

时间:2016-04-13 13:01:43

标签: python machine-learning keras

我使用jupyter笔记本和anaconda。我首先使用kerast,我不能做教程。关于这个问题是stackoverflow中的两个主题,但是找不到解决方法。

我的代码:

model = Sequential()
model.add(Dense(1, input_dim=1, activation='softmax'))

model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])

X_train_shape = X_train.reshape(len(X_train), 1)
Y_train_shape = Y_train.reshape(len(Y_train), 1)
model.fit(X_train, Y_train, nb_epoch=5, batch_size=32)

我有错误,这是一些随机的,有时一两个时代的竞争:

  

大纪元1/5 4352/17500 [======> .......................]

     

----------------------------------------------- ---------------------------- ValueError Traceback(最近一次调用   最后)in()         32个样本中的2个         3 #sleep(0.1)   ----> 4 model.fit(X_train,Y_train,nb_epoch = 5,batch_size = 32)         5 #sleep(0.1)

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ keras \ models.pyc in fit(self,   x,y,batch_size,nb_epoch,verbose,callbacks,validation_split,   validation_data,shuffle,class_weight,sample_weight,** kwargs)       395 shuffle = shuffle,       396 class_weight = class_weight,    - > 397 sample_weight = sample_weight)       398       399 def evaluate(self,x,y,batch_size = 32,verbose = 1,

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ keras \ engine \ training.pyc in   适合(self,x,y,batch_size,nb_epoch,verbose,callbacks,   validation_split,validation_data,shuffle,class_weight,   sample_weight)1009 verbose = verbose,   callbacks = callbacks,1010
  val_f = val_f,val_ins = val_ins,shuffle = shuffle,    - > 1011 callback_metrics = callback_metrics)1012 1013 def   evaluate(self,x,y,batch_size = 32,verbose = 1,sample_weight = None):

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ keras \ engine \ training.pyc in   _fit_loop(self,f,ins,out_labels,batch_size,nb_epoch,verbose,callbacks,val_f,val_ins,shuffle,callback_metrics)       753 batch_logs [l] = o       754    - > 755 callbacks.on_batch_end(batch_index,batch_logs)       756       757 epoch_logs = {}

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ keras \ callbacks.pyc in   on_batch_end(self,batch,logs)        58 t_before_callbacks = time.time()        59用于self.callbacks中的回调:   ---> 60 callback.on_batch_end(批处理,日志)        61 self._delta_ts_batch_end.append(time.time() - t_before_callbacks)        62 delta_t_median = np.median(self._delta_ts_batch_end)

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ keras \ callbacks.pyc in   on_batch_end(self,batch,logs)       187#将由on_epoch_end处理       188如果self.verbose和self.seen< self.params [ 'nb_sample']:    - > 189 self.progbar.update(self.seen,self.log_values)       190       191 def on_epoch_end(self,epoch,logs = {}):

     

C:\ Anaconda3 \ ENVS \ py27 \ lib中\站点包\ keras \ utils的\ generic_utils.pyc   在更新(自我,当前,价值)       110 info + =((prev_total_width - self.total_width)*“”)       111    - > 112 sys.stdout.write(info)       113 sys.stdout.flush()       114

     

C:\ Anaconda3 \ envs \ py27 \ lib \ site-packages \ ipykernel \ iostream.pyc in   写(自我,字符串)       315       316 is_child =(不是self._is_master_process())    - > 317 self._buffer.write(string)       318 if is_child:       319 #newlines暗示在子流程中刷新

     

ValueError:关闭文件的I / O操作

1 个答案:

答案 0 :(得分:6)

更改您的详细级别 model.fit() 至     verbose=0.
github.com/fchollet/keras/issues/2110

这不是一个直接的“修复”,但它应该有助于缓解与更新iPython控制台相关的竞争条件。