Tensorflow的client里的session.py模块

本文档介绍了TensorFlow客户端的Session接口,包括Session和InteractiveSession。这两个类并未直接实现`run()`方法,而是继承自BaseSession的`run()`方法,用于执行计算图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

session.py-------"""A client interface for TensorFlow."""

object->SessionInterface->BaseSession->Session

object->SessionInterface->BaseSession->InteractiveSession

Session和InteractiveSession里没有run()方法,而是调用父类的run()

BaseSession中run方法:

 def run(self, fetches, feed_dict=None, options=None, run_metadata=None):
    """Runs operations and evaluates tensors in `fetches`.

    This method runs one "step" of TensorFlow computation, by
    running the necessary graph fragment to execute every `Operation`
    and evaluate every `Tensor` in `fetches`, substituting the values in
    `feed_dict` for the corresponding input values.

    The `fetches` argument may be a single graph element, or an arbitrarily
    nested list, tuple, namedtuple, or dict containing graph elements at its
    leaves.  A graph element can be one of the following types:

   
RuntimeError Traceback (most recent call last) RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd --------------------------------------------------------------------------- ImportError Traceback (most recent call last) ImportError: numpy.core.multiarray failed to import The above exception was the direct cause of the following exception: SystemError Traceback (most recent call last) SystemError: <built-in method __contains__ of dict object at 0x00000270A84016C0> returned a result with an error set The above exception was the direct cause of the following exception: ImportError Traceback (most recent call last) <ipython-input-14-dbaa570f4a68> in <module> 1 # 导入 TensorFlow 并验证 ----> 2 import tensorflow as tf 3 print("TensorFlow 版本:", tf.__version__) 4 print("GPU 是否可用:", tf.config.list_physical_devices('GPU')) C:\StFiles\Anaconda\lib\site-packages\tensorflow\__init__.py in <module> 36 import typing as _typing 37 ---> 38 from tensorflow.python.tools import module_util as _module_util 39 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader 40 C:\StFiles\Anaconda\lib\site-packages\tensorflow\python\__init__.py in <module> 35 36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow ---> 37 from tensorflow.python.eager import context 38 39 # pylint: enable=wildcard-import C:\StFiles\Anaconda\lib\site-packages\tensorflow\python\eager\context.py in <module> 32 from tensorflow.python import pywrap_tfe 33 from tensorflow.python import tf2 ---> 34 from tensorflow.python.client import pywrap_tf_session 35 from tensorflow.python.eager import cancellation 36 from tensorflow.python.eager import execute C:\StFiles\Anaconda\lib\site-packages\tensorflow\python\client\pywrap_tf_session.py in <module> 17
03-29
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 41, in <module> from tensorflow.python.tools import module_util as _module_util File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 41, in <module> from tensorflow.python.eager import context File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\eager\context.py", line 38, in <module> from tensorflow.python.client import pywrap_tf_session File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\pywrap_tf_session.py", line 23, in <module> from tensorflow.python.client._pywrap_tf_session import * AttributeError: _ARRAY_API not found A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 41, in <module> from tensorflow.python.tools import module_util as _module_util File "D:\Anaconda\Anaconda3\envs\tensorflow\lib\site-packages
03-26
import tensorflow as tf from tensorflow.python.eager import benchmarks # 强制使用FP16 tf.keras.mixed_precision.set_global_policy('mixed_float16') # 运行官方基准 benchmarks.device_benchmark.main( num_iters=1000, models=['ResNet50'], batch_size=128, use_synthetic_data=True ) 运行报错 jp@jp-Super-Server:~/test$ python3 TensorFlow_FP16.py 2025-06-18 11:54:34.520927: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-06-18 11:54:34.918603: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1750218875.076606 32635 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered E0000 00:00:1750218875.121466 32635 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered W0000 00:00:1750218875.480170 32635 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once. W0000 00:00:1750218875.480230 32635 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once. W0000 00:00:1750218875.480233 32635 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once. W0000 00:00:1750218875.480236 32635 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once. 2025-06-18 11:54:35.521581: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Traceback (most recent call last): File "/home/jp/test/TensorFlow_FP16.py", line 2, in <module> from tensorflow.python.eager import benchmarks ImportError: cannot import name 'benchmarks' from 'tensorflow.python.eager' (/home/jp/.local/lib/python3.10/site-packages/tensorflow/python/eager/__init__.py)
最新发布
06-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值