Number of tensors mismatch for embeddings in the TensorBoard callback of Keras

岁酱吖の 提交于 2019-12-07 09:21:19

问题


I am using the CIFAR-10 dataset, so there are 10000 test images. I successfully created a .tsv file containing the metadata: the test set's labels (in human-readable text, not the indexes) on each of the 10000 rows.

However, in TensorBoard when I open the embedding tab, I get this error:

Number of tensors (16128) do not match the number of lines in metadata (10000).

But I would expect embeddings to be taken on the test set which is normally properly of length 10000, as in the .tsv file I made!

Here is the code I use from this project:

K.set_learning_phase(1)

# [...]

model = build_model(hype_space)

# [...]

log_path = None

if log_for_tensorboard:
    log_path = os.path.join(TENSORBOARD_DIR, model_uuid)
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    print("Tensorboard log files will be saved to: {}".format(log_path))

    embeddings_metadata = {
        # Dense layers only:
        l.name: "../test_classes.tsv"
        for l in model.layers if 'dense' in l.name.lower()
    }

    tb_callback = keras.callbacks.TensorBoard(
        log_dir=log_path,
        histogram_freq=1,
        write_graph=True,
        write_images=True
        embeddings_freq=3,
        embeddings_layer_names=list(embeddings_metadata.keys()),
        embeddings_metadata=embeddings_metadata
    )
    tb_callback.set_model(model)

    callbacks.append(tb_callback)

history = model.fit(
    [x_train],
    [y_train, y_train_c],
    batch_size=int(hype_space['batch_size']),
    epochs=EPOCHS,
    shuffle=True,
    verbose=1,
    callbacks=callbacks,
    validation_data=([x_test], [y_test, y_test_coarse])
).history

Thanks

来源:https://stackoverflow.com/questions/45178982/number-of-tensors-mismatch-for-embeddings-in-the-tensorboard-callback-of-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!