训练崩溃原因:保存模型时出现”tensorflow.GraphDef在序列化过程中被并发修改”

我目前正在尝试训练一个模型,我的输入管道是根据这里的答案构建的。我希望在每个epoch之后保存模型。但在训练了几个epoch后,训练就崩溃了。我了解到这是因为它将输入作为常量张量添加到图中。有人建议使用tf.placeholder来解决这个问题。不幸的是,这对我来说并没有解决问题。输入管道如下所示:

....filenames = [P_1]dataset = tf.data.TFRecordDataset(filenames)def _parse_function(example_proto):       keys_to_features = { 'data':tf.VarLenFeature(tf.float32)},       parsed_features = tf.parse_single_example(example_proto,  keys_to_features)       return tf.sparse_tensor_to_dense(parsed_features['data'])# Parse the record into tensors.dataset = dataset.map(_parse_function)# Shuffle the datasetdataset = dataset.shuffle(buffer_size=1000)# Repeat the input indefinitly dataset = dataset.repeat()      # Generate batches     dataset = dataset.batch(Batch_size) # Create a one-shot iteratoriterator = dataset.make_one_shot_iterator()data = iterator.get_next()   ....for i in range(epochs):    for ii in range(iteration):        image = sess.run(data)        ....     saver.save(sess, 'filename')

错误信息如下:

[libprotobuf FATAL external/protobuf_archive/src/google/protobuf/message_lite.cc:68] CHECK failed: (byte_size_before_serialization) == (byte_size_after_serialization): tensorflow.GraphDef was modified concurrently during serialization.terminate called after throwing an instance of 'google::protobuf::FatalException'  what():  CHECK failed: (byte_size_before_serialization) == (byte_size_after_serialization): tensorflow.GraphDef was modified concurrently during serialization.Aborted

回答:

问题似乎出在_parse_function中。请确保解析器在创建TFrecord文件时使用相同的方式。例如,确保它们具有相同的数据类型等。

Related Posts

在使用k近邻算法时,有没有办法获取被使用的“邻居”?

我想找到一种方法来确定在我的knn算法中实际使用了哪些…

Theano在Google Colab上无法启用GPU支持

我在尝试使用Theano库训练一个模型。由于我的电脑内…

准确性评分似乎有误

这里是代码: from sklearn.metrics…

Keras Functional API: “错误检查输入时:期望input_1具有4个维度,但得到形状为(X, Y)的数组”

我在尝试使用Keras的fit_generator来训…

如何使用sklearn.datasets.make_classification在指定范围内生成合成数据?

我想为分类问题创建合成数据。我使用了sklearn.d…

如何处理预测时不在训练集中的标签

已关闭。 此问题与编程或软件开发无关。目前不接受回答。…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注