记录tensorflow cpu版本安装

已有:anaconda环境

  • 创建虚拟环境

    conda create -n tf_cpu python=3.9.0

  • 进入虚拟环境

    activate tf_cpu

可以选择设置下载源

复制代码
# 查看当前下载源
conda config --show-sources
# 添加下载源
# 清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 中科大镜像源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
# 添加下载源后,设置搜索时显示通道地址
conda config --set show_channel_urls yes
# 删除下载源
#conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  • 安装tensorflow

    pip install tensorflow-cpu

有点久的,慢慢等。

安装成功后,看看

复制代码
(tf_cpu) C:\Windows\System32>python
Python 3.9.0 (default, Nov 15 2020, 08:30:55) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2024-03-05 14:57:59.295381: I tensorflow/core/util/port.cc:113] 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`.
WARNING:tensorflow:From D:\Software\Installation_path\Python_about\Anaconda3\envs\tf_cpu\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

>>> import tensorflow
>>> print(tensorflow.__version__)
2.15.0
>>> quit()

有个提示,但是无碍。

后面试了一下,项目导包也可以成功用了。

复制代码
import tensorflow as tf
from tensorflow import keras
.........
#这不是完整的代码哦
base_model = tf.keras.applications.efficientnet.EfficientNetB3(include_top= False, weights= "imagenet", input_shape= img_shape, pooling= 'max')

tf.keras.applications.efficientnet.EfficientNetB3为了这句能正常跑,装了很多遍。

之前一直是jupter文件一句一句运行中间有问题,不知道为啥

后面直接一个python文件运行是可以的,所以之前的版本可能也是可以的。

相关推荐
勤奋的大熊猫12 小时前
Python 双层 enumerate 循环选取最后一层循环的优雅写法
python
JYCJ_12 小时前
星愿池·子项清单
python
Wang's Blog12 小时前
Java 项目实战: 交友项目 - 动态查询开工:昨日回顾与今日任务
java·python·交友
2601_9679791212 小时前
0 到 1 学爬虫:用 Python 爬取网页数据指南一(附实战案例)
爬虫·python·实战案例·html解析·网页数据
2601_9653053912 小时前
森林防火卡口与气象监测联动
人工智能
云和数据.ChenGuang12 小时前
光哥说Python 异常深度解析:从异常模型到工程化实践
java·前端·人工智能·python·langchain
爱签AI电子合同12 小时前
电子合同全维度实测与选型指南
大数据·人工智能
AI办公探索者12 小时前
从SaaS到本地部署:大模型推理成本优化与8888元私有化方案的技术解析
大数据·人工智能
SelectDB12 小时前
云数仓月度账单总是超预算:Apache Doris 与 Snowflake 五类成本项拆解与对账脚本
python
吕布辕门12 小时前
DeepSeek 大模型落地应用与价值实现指南
人工智能·机器学习