gpt4 book ai didi

python - “NoneType”对象没有属性 'raise_exception_on_not_ok_status'

转载 作者:行者123 更新时间:2023-12-01 07:10:47 24 4
gpt4 key购买 nike

当我定义一个函数来执行神经网络训练时,出现错误。但是,当我这样做而不使其发挥作用时,就没有错误。为什么?

def myneural():

import numpy as np
import keras
from keras import backend as K
from keras.layers import Input, Dense, Activation
from keras.models import Model, Sequential


x_train_s = np.random.randint(5, size=(20, 2))
x_test_s = x_train_s

model = Sequential([
Dense(10, input_shape=(2,)),
Activation('linear'),
Dense(2),
Activation('linear')
])


model.compile(optimizer='adam', loss='mean_squared_error')

fittingadam = model.fit(x_train_s, x_train_s, epochs=2,
validation_data=(x_test_s, x_test_s),
shuffle=True, verbose=1, batch_size=None)


encoder = K.function([model.layers[0].input],
[model.layers[1].output])

code = encoder([x_test_s])[0]



myneural()

我得到的错误是:

Using TensorFlow backend.
WARNING:tensorflow:From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Train on 20 samples, validate on 20 samples
Epoch 1/2
2019-10-03 14:34:50.275279: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

20/20 [==============================] - 0s 7ms/step - loss: 4.0432 - val_loss: 3.9670
Epoch 2/2

20/20 [==============================] - 0s 53us/step - loss: 3.9670 - val_loss: 3.8917
Exception ignored in: <function BaseSession._Callable.__del__ at 0x0000021A829C1378>
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1453, in __del__
AttributeError: 'NoneType' object has no attribute 'raise_exception_on_not_ok_status'

Process finished with exit code 0

但是,当我删除第一行和最后一行并删除其他行的缩进时,不会出现错误。

第一个问题:这是为什么?我怎样才能解决它作为函数运行而不出现任何问题?

第二个问题:警告怎么样?它们重要吗?我怎样才能摆脱它们?

最佳答案

  • 您应该更新您的 tensorflow 。如果您已经使用最新版本(我对此表示怀疑),或者您受到其他软件包的约束,请忽略此异常。这是一个被抑制的异常,在解释器清理期间抛出。您可以“控制”是否抛出异常这一事实纯属巧合。
  • 这些是为直接使用tensorflow的人准备的,所以在你的例子中是keras。这不太好,但你无法对它们做任何事情,除了检查他们的错误报告者是否已经列出了这些警告。

所以一般来说:只要它执行您想要的操作并且末尾有退出代码 0,请忽略所有警告和异常。

关于python - “NoneType”对象没有属性 'raise_exception_on_not_ok_status',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58227235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com