拟合 Keras 模型时抑制输出
Supressing the output when fitting a Keras model
我用Keras设计了一个神经网络,定义模型后的代码如下:
model.compile(optimizer= 'Adam',loss='mean_squared_error')
##callbacks
cb_checkpoint = ModelCheckpoint("model.h5", monitor='val_loss', save_weights_only=True,save_best_only=True, save_freq=1)
cb_Early_Stop=EarlyStopping( monitor='val_loss',patience=5)
cb_Reduce_LR = ReduceLROnPlateau(monitor='val_loss', factor=0.3, patience=5, verbose=0, mode='auto', min_delta=0.0001,
cooldown=0, min_lr=0)
callbacks = [cb_checkpoint,cb_Early_Stop,cb_Reduce_LR]
history = model.fit(
x = {'inputsA': inputsA, 'inputsB': inputsB, 'inputsC': inputsC, 'inputsD': inputsD, 'input_site_id': site_id, 'input_building_id': building_id,
'input_meter': meter, 'input_primary_use': primary_use,
'input_week': week, 'input_floor_count': floor_count, 'input_month': month, 'input_hour': hour} , y = {'predictions' : target}, batch_size = 16, epochs = 1000,
validation_split = 0.1,
callbacks=callbacks)
当我开始拟合过程时,我在第一个时期得到了这种输出:
Train on 1799857 samples, validate on 199985 samples
Epoch 1/1000
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
16/1799857 [..............................] - ETA: 60:50:41 - loss: 77.3295WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
112/1799857 [..............................] - ETA: 8:55:07 - loss: 112.8611WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
208/1799857 [..............................] - ETA: 4:55:23 - loss: 87.5595 WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
320/1799857 [..............................] - ETA: 3:17:30 - loss: 78.3782WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
432/1799857 [..............................] - ETA: 2:29:53 - loss: 70.0334WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
我想抑制此输出并仅在每个纪元结束时获得关于火车和 val 损失的更新。
我怎样才能做到这一点?
如 keras documentation 中所写,如果输入是生成器或序列,则 validation_split
将不起作用。
您可以提供 validation_data
参数。
我用Keras设计了一个神经网络,定义模型后的代码如下:
model.compile(optimizer= 'Adam',loss='mean_squared_error')
##callbacks
cb_checkpoint = ModelCheckpoint("model.h5", monitor='val_loss', save_weights_only=True,save_best_only=True, save_freq=1)
cb_Early_Stop=EarlyStopping( monitor='val_loss',patience=5)
cb_Reduce_LR = ReduceLROnPlateau(monitor='val_loss', factor=0.3, patience=5, verbose=0, mode='auto', min_delta=0.0001,
cooldown=0, min_lr=0)
callbacks = [cb_checkpoint,cb_Early_Stop,cb_Reduce_LR]
history = model.fit(
x = {'inputsA': inputsA, 'inputsB': inputsB, 'inputsC': inputsC, 'inputsD': inputsD, 'input_site_id': site_id, 'input_building_id': building_id,
'input_meter': meter, 'input_primary_use': primary_use,
'input_week': week, 'input_floor_count': floor_count, 'input_month': month, 'input_hour': hour} , y = {'predictions' : target}, batch_size = 16, epochs = 1000,
validation_split = 0.1,
callbacks=callbacks)
当我开始拟合过程时,我在第一个时期得到了这种输出:
Train on 1799857 samples, validate on 199985 samples
Epoch 1/1000
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
16/1799857 [..............................] - ETA: 60:50:41 - loss: 77.3295WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
112/1799857 [..............................] - ETA: 8:55:07 - loss: 112.8611WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
208/1799857 [..............................] - ETA: 4:55:23 - loss: 87.5595 WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
320/1799857 [..............................] - ETA: 3:17:30 - loss: 78.3782WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
432/1799857 [..............................] - ETA: 2:29:53 - loss: 70.0334WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
WARNING:tensorflow:Can save best model only with val_loss available, skipping.
我想抑制此输出并仅在每个纪元结束时获得关于火车和 val 损失的更新。
我怎样才能做到这一点?
如 keras documentation 中所写,如果输入是生成器或序列,则 validation_split
将不起作用。
您可以提供 validation_data
参数。