训练崩溃原因:保存模型时出现”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折交叉验证的直观问题

我在使用交叉验证检查预测能力时遇到了一些直观问题,我认…

调整numpy数组大小以使用sklearn的train_test_split函数?

我正在尝试使用sklearn中的test_train_…

如何转换二维张量和索引张量以便用于torch.nn.utils.rnn.pack_sequence

我有一组序列,格式如下: sequences = to…

模型预测值的含义是什么?

我在网上找到一个数字识别器的CNN模型并进行了训练,当…

锯齿张量作为LSTM的输入

了解锯齿张量以及如何在TensorFlow中使用它们。…

如何告诉SciKit的LinearRegression模型预测值不能小于零?

我有以下代码,尝试根据非价格基础特征来估值股票。 pr…

发表回复

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