2016-04-13 3 views
9

J'utilise jupyter notebook avec anaconda. J'utilise kerast d'abord, et je ne peux pas faire de tutoriel. A propos de ces problèmes sont deux thèmes dans stackoverflow, mais résolument introuvable.Keras. ValueError: opération d'E/S sur fichier fermé

Mon code:

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) 

Et je erreur, il est un peu au hasard et parfois un ou deux époque ont concouru:

Epoch 1/5 4352/17500 [======>.......................]

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) in() 2 # of 32 samples 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 fit(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 for callback in self.callbacks: ---> 60 callback.on_batch_end(batch, logs) 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 # will be handled by on_epoch_end 188 if self.verbose and 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\site-packages\keras\utils\generic_utils.pyc in update(self, current, values) 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 write(self, string) 315 316 is_child = (not self._is_master_process()) --> 317 self._buffer.write(string) 318 if is_child: 319 # newlines imply flush in subprocesses

ValueError: I/O operation on closed file

+3

Le problème disparaît-il si vous changez votre niveau verbeux dans model.fit() en verbose = 0? Voir github.com/fchollet/keras/issues/2110 –

+0

Cela a fonctionné pour moi. Merci de l'avoir posté. – jss367

+0

@ Amw5G Pourriez-vous poster une réponse? –

Répondre

2

Changer votre niveau verbeux dans model.fit() à verbose=0.
Voir github.com/fchollet/keras/issues/2110

Ce n'est pas un "correctif" direct, mais il devrait aider à atténuer une condition de concurrence associée à la mise à jour de la console iPython.