tensorflow malloc 错误“释放的指针未分配”

问题描述 投票:0回答:1

我在尝试运行我的张量流代码时突然遇到此错误。以前工作得很好,但现在突然出现这个错误。谷歌搜索后,只有一处提到 Tensorflow 中弹出此错误,但修复方法是升级到 tf 1.7(这是 5 年前)。我正在尝试使用tensorflow 2.15运行它。

预期的行为是在禁用 v2 行为的情况下运行 $sess.run(..)$ 以获得急切执行模式下的基本预测时不会崩溃。

相反,我在完整的堆栈跟踪的底部收到错误:

WARNING:tensorflow:From /opt/homebrew/anaconda3/lib/python3.11/site-packages/tensorflow/python/compat/v2_compat.py:108: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
/Users/paullintilhac/code/pdfclassifier/train/model.py:18: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.
  h_fc1 = tf.layers.dense(self.x_input, 200, activation=tf.nn.relu, name="fc1")
/Users/paullintilhac/code/pdfclassifier/train/model.py:19: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.
  h_fc2 = tf.layers.dense(h_fc1, 200, activation=tf.nn.relu, name="fc2")
/Users/paullintilhac/code/pdfclassifier/train/model.py:21: UserWarning: `tf.layers.dense` is deprecated and will be removed in a future version. Please use `tf.keras.layers.Dense` instead.
  self.pre_softmax = tf.layers.dense(h_fc2, 2, activation=None, name="pre_softmax")
python3(1815,0x1e0f91ec0) malloc: *** error for object 0x2a8987964: pointer being freed was not allocated
python3(1815,0x1e0f91ec0) malloc: *** set a breakpoint in malloc_error_break to debug

这是我非常简单的代码示例(这与我在运行更复杂的程序时遇到的错误完全相同):

import tensorflow.compat.v1 as tf
from model import Model
tf.disable_eager_execution()
tf.disable_v2_behavior()
x_test = [[float(0)]*3514]
model = Model()
saver = tf.train.Saver()
with tf.Session() as sess:
    PATH = "../models/adv_trained/baseline_adv_combine_two.ckpt"
    saver.restore(sess, PATH)
    y = sess.run(model.y_pred,\
                        feed_dict={model.x_input:x_test
                })

任何帮助将不胜感激!

最好的,

保罗

tensorflow malloc
1个回答
0
投票

我自己从未遇到过这个问题,但 TF2 文档明确指出:

tf.compat.v1.train.Saver
不支持在 TF2 中保存和恢复检查点。请切换到
tf.train.Checkpoint
tf.keras.Model.save_weights
,它们执行更强大的基于对象的保存。

因此,我会尝试使用这些其他功能来恢复 TF1 会话并将其转换为 TF2 格式,如“如何重写检查点”部分中所述...

© www.soinside.com 2019 - 2024. All rights reserved.