Keras Tensorboard回调未记录标量(损失)

时间:2019-06-20 06:46:14

标签: python tensorflow keras tensorboard

我一直在使用keras tensorboard回调,并且运行良好。本周,我编写了一个新代码,即使我在model.compile()语句中指定了指标,回调也不再存储标量。

即使没有指定度量标准,默认情况下它也可以用来捕获早期代码中每次迭代后的损失。

最后检查一下tensorboard安装是否存在问题,我尝试再次运行旧代码,它似乎运行正常,但新代码却没有。新旧代码之间的唯一区别是,我在新代码中使用了数据生成器,并使用了model.fit_generator()而不是model.fit()。

我尝试重新安装tensorboard,但这似乎无法解决问题。

旧代码-

def train(X,Y,val_split,checkpoint):

    model=segmenter()
    initial_epoch=0
    if checkpoint is not None:
        model.load_weights(checkpoint, by_name=True)
        initial_epoch=int(re.search(r'\d+', os.path.basename(checkpoint)).group())

    adam=Adam(lr=0.00001)
    model.compile(optimizer=adam,loss='mean_squared_error')
    filepath="checkpoint-{epoch:06d}.hdf5_50_50"
    checkpoint = ModelCheckpoint(filepath, monitor='loss', verbose=1, save_best_only=True)
    #for visualisation
    visualisation= TensorBoard(log_dir='./logs', histogram_freq=0, batch_size=BATCH_SIZE, write_graph=True, write_grads=False, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)
    callbacks_list = [checkpoint,visualisation]
    model.fit(x=X,y=Y,epochs=EPOCHS,batch_size=BATCH_SIZE, validation_split=val_split,callbacks=callbacks_list, shuffle=True, initial_epoch=initial_epoch )

新代码-

def train(namelistfile,val_split=0.1,checkpoint=None,batch_size=1):

    #getting file names
    with open(namelistfile,'r') as f:
        namelist=[line.replace('\n','') for line in f ]

    # Generators
    split=int((1-val_split)*len(namelist))
    training_generator = mygenerator(namelist=namelist[:split], batch_size=batch_size)
    validation_generator = mygenerator(namelist=namelist[split:], batch_size=batch_size)

    # Training
    model=autoencoder()
    model.summary()
    initial_epoch=0
    if checkpoint is not None:
        model.load_weights(checkpoint,by_name=True)
        initial_epoch=int(re.search(r'\d+', os.path.basename(checkpoint)).group())
    adam=Adam(lr=0.001) 
    model.compile(optimizer=adam,loss='mean_squared_error',metrics=['mean_squared_error'])
    filepath="checkpoint-{epoch:06d}.hdf5"
    checkpoint = ModelCheckpoint(filepath, monitor='loss', verbose=1, save_best_only=True)
    #for visualisation
    visualisation= TensorBoard(log_dir='./logs', histogram_freq=0, batch_size=batch_size, write_graph=True, write_grads=False, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)
    callbacks_list = [checkpoint,visualisation]
    model.fit_generator(generator=training_generator,validation_data=validation_generator,epochs=EPOCHS,callbacks=callbacks_list, initial_epoch= initial_epoch, use_multiprocessing=True,workers=6)

以下是

的结果
tensorboard --inspect --logdir=logs

对于旧代码

======================================================================
Processing event files... (this can take a few minutes)
======================================================================

Found event files in:
logs

These tags are in logs:
audio -
histograms -
images -
scalars
   loss
   val_loss
tensor -
======================================================================

Event statistics for logs:
audio -
graph
   first_step           0
   last_step            0
   max_step             0
   min_step             0
   num_steps            1
   outoforder_steps     []
histograms -
images -
scalars
   first_step           301
   last_step            301
   max_step             301
   min_step             301
   num_steps            1
   outoforder_steps     []
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
tensor -
======================================================================

对于新代码


======================================================================
Processing event files... (this can take a few minutes)
======================================================================

Found event files in:
logs

These tags are in logs:
audio -
histograms -
images -
scalars -
tensor -
======================================================================

Event statistics for logs:
audio -
graph
   first_step           0
   last_step            0
   max_step             0
   min_step             0
   num_steps            1
   outoforder_steps     []
histograms -
images -
scalars -
sessionlog:checkpoint -
sessionlog:start -
sessionlog:stop -
tensor -
======================================================================


Tensorboard没有给出任何错误。似乎我丢失了一些东西,我的代码有问题。任何人都可以请我帮忙,因为没有张量板很难可视化。

TensorBoard 1.5.1
Keras 2.1.2
Tesorflow 1.4.1
Python 2.7.6 

0 个答案:

没有答案