tensorflow-gpu 2.10.0 , " 将 tensorflow._api.v2.compat.v1 导入 为 tf " 不 起 作用

ehxuflar  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(249)
import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
a = tf.constant(1)
b = tf.constant(2)
c = tf.add(a, b)
sess = tf.Session()
sess.run(c)

此代码显示:

WARNING:tensorflow:From 
C:\Users\alsgn\anaconda3\lib\site- 
packages\tensorflow\python\compat\v2_compat.py:107: 
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
2022-10-19 00:58:09.139243: I 
tensorflow/core/platform/cpu_feature_guard.rd.cc:193] 
This TensorFlow binary is optimized with oneAPI Deep 
Neuraltwo Network Library (oneDNN) to use the following 
CPU instructions in perce-formance-critical operations:  
AVX AVX2
To enable them in other operations, rebuild TensorFlow 
with the appropriariate compiler flags.
2022-10-19 00:58:09.427606: I 
tensorflow/core/common_runtime/gpu/gpu_devievice.cc:1616] 
Created device /job:localhost/replica:0/task:0/device:G0 wPU:0 with 5467 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3070bus, pci bus id: 0000:01:00.0, compute capability: 8.6
2022-10-19 00:58:09.429852: I tensorflow/compiler/mlir/mlir_graph_optimizmization_pass.cc:354] MLIR V1 optimization pass is not enabled

这看起来不是错误,但是代码没有输出结果。

plicqrtu

plicqrtu1#

您的代码运行正常。请使用print()函数获得如下结果

import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
a = tf.constant(1)
b = tf.constant(2)
c = tf.add(a, b)
sess = tf.Session()
print(sess.run(c)) #Use print()

输出量:

3

相关问题