首页 > 解决方案 > 我不知道如何在 ubuntu tensorflow-gpu 上执行此操作,“E tensorflow / core / util / events_writer.cc: 104]

问题描述

我需要为这个深度学习问题写一个检查点。但是那个错误阻止我写文件。(E:在 tf.summary.FileWriter)

错误:“tensorflow/core/util/events_writer.cc:104] 写入失败,因为无法打开文件。

我试过这个。重装、删除、授权(tensorflow-gpu、tensorflow、tensorboard)

with tf.Session() as sess:
    dir = pickledir
    dic_0 = pat_level_arr(dir, 0, [0, 1])
    dic_1 = pat_level_arr(dir, 1, [1, 0])

    seed = 42
    abc = range(len(dic_0))
    abcd = range(len(dic_1))

    dic_0_train, dic_0_test, _, _ = train_test_split(
        dic_0, abc, test_size=0.244, random_state=seed)
    dic_1_train, dic_1_test, _, _ = train_test_split(
        dic_1, abcd, test_size=0.35, random_state=seed)

    dic_train = np.concatenate((dic_0_train, dic_1_train), axis=0)
    dic_test = np.concatenate((dic_0_test, dic_1_test), axis=0)
    summaries_dir = './logs_level'
#here is the problem "tensorflow/core/util/events_writer.cc:104] Write failed because file could not be opened.
======================================================================
    print("here is start\n")
    train_writer = tf.summary.FileWriter(summaries_dir + '/train', sess.graph)
    test_writer = tf.summary.FileWriter(summaries_dir + '/test')
    print("here is end\n")
======================================================================
    init = tf.global_variables_initializer()
    sess.run(init)

    # For train
    try:
        saver.restore(sess, './modelckpt/inception.ckpt')
        print('Model restored')
        epoch_saved = data_saved['var_epoch_saved'].eval()
    except tf.errors.NotFoundError:
        print('No saved model found')
        epoch_saved = 1
    except tf.errors.InvalidArgumentError:
        print('Model structure has change. Rebuild model')
        epoch_saved = 1

E tensorflow/core/util/events_writer.cc:104] 写入失败,因为无法打开文件。

ValueError:传递的 save_path 不是有效的检查点:./modelckpt/inception.ckpt

tensorflow-gpu 版本是 1.10.0。python版本是3.5(我认为)。我已经安装了张量板。

标签: pythontensorflowubuntu

解决方案


基本上,错误表明检查点文件不存在,因此它不是有效的检查点。

您需要使用以下代码保存模型,然后再执行saver.restore()方法 ,因为它从磁盘加载文件。

saver = tf.train.Saver()
with tf.Session() as sess:
  sess.run(init_op)
  # Do some work with the model.

  # Save the variables to disk.
  save_path = saver.save(sess, "/tmp/model.ckpt")

请参阅以下链接中的 Tensorflow 版本 1.x 的保存和恢复说明和代码,https://github.com/tensorflow/docs/blob/master/site/en/r1/guide/saved_model.md


推荐阅读