创建keras环境步骤

简介: 0 下载并安装miniconda

0 下载并安装miniconda

bash Miniconda3-latest-Linux-x86_64.sh 执行安装
• 1

一股YES,安装成功,但是会发现不存在。

pip list
Command 'pip' not found, but can be installed with:
sudo apt install python-pip

此时,我们对终端进行重启即可

1.首先安装anaconda
2.bash Anaconda安装包
3.在终端输入anaconda(确保已经安装完成)
4.终端输入vim ~/.bashrc
5.点击i
6.在最后一行输入export PATH=/home/XXX/anaconda3/bin:$PATH
7.按 Esc :wq保存退出
8. 在终端输入source ~/.bashrc 更新配置文件
9. 新建环境:在命令行输入conda create -n 虚拟环境名 python=2.7/3.6…(conda install --yes --file requirements.txt)
10. 激活环境:source activate 虚拟环境名
11. 查看所有环境:终端输入 conda env list

1. 安装环境

首先看系统的版本


查看cudnn版本

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
lihuanyu@zyg-dgx:~$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 3
#define CUDNN_PATCHLEVEL 1
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"

查看cuda版本

lihuanyu@zyg-dgx:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

2 创建lihuanyu环境

1 创建环境,这一过程需要下载东西,速度相对较慢。
conda create -n lihuanyu python=3.6
2 激活进入环境
conda activate lihuanyu
3 查看环境
conda info -e
4 删除环境
conda remove -n lihuanyu --all
5 添加清华镜像
5.1 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
5.2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
5.3 conda config --set show_channel_urls yes
5.4 conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/   删除
6. 退出环境
conda deactivate

3. 安装tesorflow-gpu

1 安装最新版本tensorflow-gpu 2.6.0

pip install tensorflow-gpu

利用清华镜像安装2.2.0

pip install tensorflow-gpu==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
• 1

查看GPU能用吗?

import tensorflow as tf
tf.__version__
import tensorflow as tf
tf.test.is_gpu_available()

4. 安装keras

pytho对应关系


pip install keras==2.3.1
export LD_LIBRARY_PATH="/usr/local/cuda-10.1b64:$LD_LIBRARY_PATH"

5 切换cuda

export PATH="/usr/local/cuda-10.1/bin:$PATH"
 export LD_LIBRARY_PATH="/usr/local/cuda-10.1b64:$LD_LIBRARY_PATH"
• 1
• 2

6. 测试文件(源于官方例程)

测试文件

"""
Title: Simple MNIST convnet
Author: [fchollet](https://twitter.com/fchollet)
Date created: 2015/06/19
Last modified: 2020/04/21
Description: A simple convnet that achieves ~99% test accuracy on MNIST.
"""
"""
## Setup
"""
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
"""
## Prepare the data
"""
# Model / data parameters
num_classes = 10
input_shape = (28, 28, 1)
# the data, split between train and test sets
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
# Scale images to the [0, 1] range
x_train = x_train.astype("float32") / 255
x_test = x_test.astype("float32") / 255
# Make sure images have shape (28, 28, 1)
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)
print("x_train shape:", x_train.shape)
print(x_train.shape[0], "train samples")
print(x_test.shape[0], "test samples")
# convert class vectors to binary class matrices
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)
"""
## Build the model
"""
model = keras.Sequential(
    [
        keras.Input(shape=input_shape),
        layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
        layers.MaxPooling2D(pool_size=(2, 2)),
        layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
        layers.MaxPooling2D(pool_size=(2, 2)),
        layers.Flatten(),
        layers.Dropout(0.5),
        layers.Dense(num_classes, activation="softmax"),
    ]
)
model.summary()
"""
## Train the model
"""
batch_size = 128
epochs = 15
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)
"""
## Evaluate the trained model
"""
score = model.evaluate(x_test, y_test, verbose=0)
print("Test loss:", score[0])
print("Test accuracy:", score[1])

结果为

相关实践学习
在云上部署ChatGLM2-6B大模型(GPU版)
ChatGLM2-6B是由智谱AI及清华KEG实验室于2023年6月发布的中英双语对话开源大模型。通过本实验,可以学习如何配置AIGC开发环境,如何部署ChatGLM2-6B大模型。
相关文章
|
缓存 编译器
BOLT 二进制反馈优化技术
大型应用的代码往往达到数十甚至上百MB,这导致在程序执行时缓存机制无法充分利用,导致大量时间花费在CPU和内存链路上。通过对热点函数的布局进行优化,我们可以更好地利用CPU cache,从而获得较为可观的性能提升。针对这一问题,在编译技术上有PGO和Bolt两种解决办法,两者都是一种通过收集程序在运行时如跳转,调用关系,函数热度等执行信息,这些收集到的程序运行情况数据(profile data),可以更好地指导一些程序优化的策略,如是否对函数进行内联,以及对基本块和函数布局的排布来提高特定场景下的程序性能。
3096 2
BOLT 二进制反馈优化技术
|
机器学习/深度学习 人工智能 算法
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络
垃圾识别分类系统。本系统采用Python作为主要编程语言,通过收集了5种常见的垃圾数据集('塑料', '玻璃', '纸张', '纸板', '金属'),然后基于TensorFlow搭建卷积神经网络算法模型,通过对图像数据集进行多轮迭代训练,最后得到一个识别精度较高的模型文件。然后使用Django搭建Web网页端可视化操作界面,实现用户在网页端上传一张垃圾图片识别其名称。
531 0
基于Python深度学习的【垃圾识别系统】实现~TensorFlow+人工智能+算法网络
|
缓存 Dragonfly 人工智能
带你读《2022龙蜥社区全景白皮书》——5.3.1 跨云-边-端的只读文件系统EROFS
带你读《2022龙蜥社区全景白皮书》——5.3.1 跨云-边-端的只读文件系统EROFS
298 61
|
机器学习/深度学习 数据采集 传感器
使用Python实现深度学习模型:智能极端天气事件预测
使用Python实现深度学习模型:智能极端天气事件预测
1041 3
|
NoSQL 大数据 Redis
分享5款.NET开源免费的Redis客户端组件库
分享5款.NET开源免费的Redis客户端组件库
262 1
|
存储 缓存 分布式计算
Spring-retry 使用指南
该项目为Spring应用程序提供声明式重试支持,它用于Spring Batch、Spring Integration、Apache Hadoop的Spring(以及其他),命令式重试也支持显式使用。
2322 0
Spring-retry 使用指南
|
网络协议
TCP关闭连接的两种方式
【4月更文挑战第5天】close 和 shutdown 的函数
|
关系型数据库 MySQL 数据库
mysql 查看数据库、表的基本命令
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34173549/article/details/80871834 1:show databases; 查看所有的数据库,等同于select schema_name from information_schema.schemata\G。
5856 0
|
存储 安全 前端开发
技术人员必须知道的手机验证码登录风险
技术人员必须知道的手机验证码登录风险
1197 0

热门文章

最新文章