
lawlite19


1.2w 访问量
0 原创专栏
0 资料
0 粉丝
个性签名:此E友还没有留下个性签名哦~
加入易百纳时间:2019-09-18
按发布时间
按阅读量
按点赞量
-
null 机器学习算法Python实现机器学习算法Python实现 说明 github地址:https://github.com/lawlite19/MachineLearning_Python 因为里面的公式加载出现问题,这里只给出了目录,可以去github中查看 目录 机器学习算法Python实现 一、线性回归 1、代价函数 2、梯度下降算法 3、均值归一化 4、最终运行结果 5、使用scikit-learn库中的线性模型实现 二、逻辑回归 1、代价函数 2、梯度 3、正则化 4、S型函数(即) 5、映射为多项式 6、使用的优化方法 7、运行结果 8、使用scikit-learn库中的逻辑回归模型实现 逻辑回归_手写数字识别_OneVsAll 1、随机显示100个数字 2、OneVsAll 3、手写数字识别 4、预测 5、运行结果 6、使用scikit-learn库中的逻辑回归模型实现 三、BP神经网络 1、神经网络model 2、代价函数 3、正则化 4、反向传播BP 5、BP可以求梯度的原因 6、梯度检查 7、权重的随机初始化 8、预测 9、输出结果 四、SVM支持向量机 1、代价函数 2、Large Margin 3、SVM Kernel(核函数) 4、使用中的模型代码 5、运行结果 五、K-Means聚类算法 1、聚类过程 2、目标函数 3、聚类中心的选择 4、聚类个数K的选择 5、应用——图片压缩 6、使用scikit-learn库中的线性模型实现聚类 7、运行结果 六、PCA主成分分析(降维) 1、用处 2、2D-->1D,nD-->kD 3、主成分分析PCA与线性回归的区别 4、PCA降维过程 5、数据恢复 6、主成分个数的选择(即要降的维度) 7、使用建议 8、运行结果 9、使用scikit-learn库中的PCA实现降维 七、异常检测 Anomaly Detection 1、高斯分布(正态分布) 2、异常检测算法 3、评价的好坏,以及的选取 4、选择使用什么样的feature(单元高斯分布) 5、多元高斯分布 6、单元和多元高斯分布特点 7、程序运行结果2019-09-180 0 3528
-
null 数据结构算法练习说明 github地址:https://github.com/lawlite19/AlgorithmExercises 一、 排序算法 1. 交换排序 冒泡排序 冒泡排序改进1 冒泡排序改进2 冒泡排序改进3 快速排序 2. 插入排序 直接插入排序 直接插入排序递归版 希尔排序 3. 选择排序 简单选择排序 二元选择排序 堆排序 4. 归并排序 二路归并排序递归版 二路归并排序非递归版 二、 字符串 1. 字符串旋转 字符串旋转_暴力法 字符串旋转_三步翻转法 2. 字符串包含 字符串包含判断_遍历 字符串包含判断_排序 字符串包含判断_素数乘积 字符串包含判断_哈希 ★★★ 3. 回文 回文判断 4. 最长回文子串长度 最长回文子串长度_一般解法 最长回文子串长度_Manacher ★★★ 算法说明 5. 全排列 全排列_递归 全排列_字典序排列 字典序全排列 6. 变形词 变形词判断 7. 字符串中数字串之和 字符串中数字串之和 ★ 8. 去除字符串中连续K个0串 去除字符串中连续K个0串 9. 整数字符串转整数值 整数字符串转整数值 ★★ 10. 字符串匹配问题 字符串匹配_KMP ★★★★★ 算法说明 三、 数组和矩阵 1. 二维数组查找 二维数组查找 2. 矩阵相关操作 转圈打印矩阵 3. 最小的k个元素 最小的k个元素_堆 最小的k个元素_BFPRT ★★★★★ 算法说明 4.中间数 中间数_辅助数组 ★ 5.非负数组和为K的最长子数组 非负数组和为K的最长子数组_双指针 ★★★ 8.次数出现大于N/K的数 次数出现大于N/2的数 ★ 次数出现大于N/K的数 ★★★ 9.逆序对 逆序对数_分治归并★ 10.两个有序数组的中位数 两个有序数组的中位数_分治★★★★ 算法说明 四、 递归和动态规划 1. 斐波那契问题 矩形覆盖_递归 矩形覆盖_dp ★ 矩阵覆盖_矩阵转化_class实现 ★★★ 矩阵覆盖_矩阵转化_vector实现 ★★★ 算法说明 爬楼梯_递归 爬楼梯_dp ★ 变态跳台阶_递归 变态跳台阶_直接计算 ★ 2. 最大子数组和相关问题 最大子数组和_dp ★ 两个不相容子数组最大和_辅助数组 ★★ 3. 最长递增子序列相关问题 最长递增子序列_一般dp 最长递增子序列_dp优化 ★★ 摞数组问题(俄国沙皇问题)_纯代码实现 ★★★★ 摞数组问题(俄国沙皇问题)_借助stl ★★★★ 五、 栈和队列 1. getMin功能栈 getMin功能栈_方案1 getMin功能栈_方案2 2. 两个栈实现队列功能 两个栈实现队列 七、二叉树 1. 遍历 先、中、后序遍历_递归 先、中、后序遍历_非递归 ★★ 八、位运算 出现奇数次的数2019-09-180 0 2517
-
null 风格迁移 Style transfer一、介绍 将一张图片的艺术风格应用在另外一张图片上 使用深度卷积网络CNN提取一张图片的内容和提取一张图片的风格, 然后将两者结合起来得到最后的结果 二、 方法 我们知道 CNN 可以捕捉图像的高层次特征,如上图所示,内容图片经过CNN可以得到对应的图像表述(representation, 就是经过卷积操作的feature map),然后经过重构可以得到近似原图的效果 特别是前面几层经过重构得到的结果和原图更接近,也说明前几层保留的图片细节会更多,因为后面还有pooling层,自然会丢弃调一些信息 这里的网络使用的是VGG-16 (如下图),包含 13 个卷积层,3 个全连接层 1、内容损失 假设一个卷积层包含 ${N_l}$ 个过滤器 filters,则可以得到 ${N_l}$ 个feature maps,假设 feature map的大小是 $M_l$ (长乘宽),则可以通过一个矩阵来存储 l 层的数据 $$F^l \in R^{N_l \times M_l} $$ $F^l_{i,j}$ 表示第 l 层的第 i 个filter 在 j 位置上的激活值 所以现在一张内容图片$\overrightarrow p$,一张生成图片$\overrightarrow x$(初始值为高斯分布), 经过一层卷积层l可以得到其对应的特征表示:$P^l$ 和 $Fl$, 则对应的损失采用均方误差: $$L{content}(\overrightarrow p, \overrightarrow x, l) = {1 \over 2} \sum{ij}(F^l{ij}-P^l_{ij})^2$$ $F$ 和 $P$是两个矩阵,大小是$N_l \times M_l$,即l层过滤器的个数 和 feature map 的长乘宽的值 2、风格损失 风格的表示这里采用格拉姆矩阵(Gram Matrix): $G^l \in R^{N_l \times Nl}$ $$G^l{ij} = {\sumk F^l{ik}F^l_{jk}}$$ 格拉姆矩阵计算的是两两特征的相关性 , 即哪两个特征是同时出现的,哪两个特征是此消彼长的等,能够保留图像的风格 ( 比如一幅画中有人和树,它们可以出现在任意位置,格拉姆矩阵可以衡量它们之间的关系,可以认为是这幅画的风格信息 ) 假设$\overrightarrow a$是风格图像,$\overrightarrow x$是生成图像,$A^l$ 和 $G^l$ 表示在 $l$ 层的格拉姆矩阵,则这一层的损失为:$$E_l = {1 \over 4N^2_lM^2l}{\sum{i,j} (G^l{ij}-A^l{ij})^2}$$ 提取风格信息是我们会使用多个卷积层的输出,所以总损失为:$$L_{style}(\overrightarrow a, \overrightarrow x) = {\sum^L_lw_lE_l}$$ 这里$w_l$是每一层损失的权重 3、总损失函数 通过白噪声初始化(就是高斯分布)一个输出的结果,然后通过网络对这个结果进行风格和内容两方面的约束进行修正 $$L{total}(\overrightarrow p,\overrightarrow a,\overrightarrow x)=\alpha L{content}(\overrightarrow p, \overrightarrow x) +\beta L_{style}(\overrightarrow a, \overrightarrow x)$$ 三、代码实现 1、说明 全部代码:点击查看 图像使用一张建筑图和梵高的星空 2、加载并预处理图片和初始化输出图片 输出图片采用高斯分布初始化 import numpy as np from keras import backend as K from keras.applications.vgg16 import preprocess_input from keras.preprocessing.image import load_img, img_to_array from keras.applications import VGG16 from scipy.optimize import fmin_l_bfgs_b from matplotlib import pyplot as plt '''图片路径''' content_image_path = './data/buildings.jpg' style_image_path = './data/starry-sky.jpg' generate_image_path = './data/output.jpg' '''加载图片并初始化输出图片''' target_height = 512 target_width = 512 target_size = (target_height, target_width) content_image = load_img(content_image_path, target_size=target_size) content_image_array = img_to_array(content_image) content_image_array = K.variable(preprocess_input(np.expand_dims(content_image_array, 0)), dtype='float32') style_image = load_img(style_image_path, target_size=target_size) style_image_array = img_to_array(style_image) style_image_array = K.variable(preprocess_input(np.expand_dims(style_image_array, 0)), dtype='float32') generate_image = np.random.randint(256, size=(target_width, target_height, 3)).astype('float64') generate_image = preprocess_input(np.expand_dims(generate_image, 0)) generate_image_placeholder = K.placeholder(shape=(1, target_width, target_height, 3)) 3、获取网络中对应层的输出 def get_feature_represent(x, layer_names, model): '''图片的特征图表示 参数 ---------------------------------------------- x : 输入, 这里并没有使用,可以看作一个输入的标识 layer_names : list CNN网络层的名字 model : CNN模型 返回值 ---------------------------------------------- feature_matrices : list 经过CNN卷积层的特征表示,这里大小是(filter个数, feature map的长*宽) ''' feature_matrices = [] for ln in layer_names: select_layer = model.get_layer(ln) feature_raw = select_layer.output feature_raw_shape = K.shape(feature_raw).eval(session=tf_session) N_l = feature_raw_shape[-1] M_l = feature_raw_shape[1]*feature_raw_shape[2] feature_matrix = K.reshape(feature_raw, (M_l, N_l)) feature_matrix = K.transpose(feature_matrix) feature_matrices.append(feature_matrix) return feature_matrices 4、内容损失函数 def get_content_loss(F, P): '''计算内容损失 参数 --------------------------------------- F : tensor, float32 生成图片特征图矩阵 P : tensor, float32 内容图片特征图矩阵 返回值 --------------------------------------- content_loss : tensor, float32 内容损失 ''' content_loss = 0.5*K.sum(K.square(F-P)) return content_loss 5、Gram矩阵和风格损失 def get_gram_matrix(F): '''计算gram矩阵''' G = K.dot(F, K.transpose(F)) return G def get_style_loss(ws, Gs, As): '''计算风格损失 参数 --------------------------------------- ws : array 每一层layer的权重 Gs : list 生成图片每一层得到的特征表示组成的list As : list 风格图片每一层得到的特征表示组成的list ''' style_loss = K.variable(0.) for w, G, A in zip(ws, Gs, As): M_l = K.int_shape(G)[1] N_l = K.int_shape(G)[0] G_gram = get_gram_matrix(G) A_gram = get_gram_matrix(A) style_loss += w*0.25*K.sum(K.square(G_gram-A_gram))/(N_l**2*M_l**2) return style_loss 6、总损失 def get_total_loss(generate_image_placeholder, alpha=1.0, beta=10000.0): '''总损失 ''' F = get_feature_represent(generate_image_placeholder, layer_names=[content_layer_name], model=gModel)[0] Gs = get_feature_represent(generate_image_placeholder, layer_names=style_layer_names, model=gModel) content_loss = get_content_loss(F, P) style_loss = get_style_loss(ws, Gs, As) total_loss = alpha*content_loss + beta*style_loss return total_loss def calculate_loss(gen_image_array): '''调用总损失函数,计算得到总损失数值''' if gen_image_array != (1, target_width, target_height, 3): gen_image_array = gen_image_array.reshape((1, target_width, target_height, 3)) loss_fn = K.function(inputs=[gModel.input], outputs=[get_total_loss(gModel.input)]) return loss_fn([gen_image_array])[0].astype('float64') 7、损失函数梯度 def get_grad(gen_image_array): '''计算损失函数的梯度''' if gen_image_array != (1, target_width, target_height, 3): gen_image_array = gen_image_array.reshape((1, target_width, target_height, 3)) grad_fn = K.function([gModel.input], K.gradients(get_total_loss(gModel.input), [gModel.input])) grad = grad_fn([gen_image_array])[0].flatten().astype('float64') return grad 8、生成结果后处理 因为之前preprocess_input函数中做了处理,这里进行逆处理还原 def postprocess_array(x): '''生成图片后处理,因为之前preprocess_input函数中做了处理,这里进行逆处理还原 ''' if x.shape != (target_width, target_height, 3): x = x.reshape((target_width, target_height, 3)) x[..., 0] += 103.939 x[..., 1] += 116.779 x[..., 2] += 123.68 x = x[..., ::-1] # BGR-->RGB x = np.clip(x, 0, 255) x = x.astype('uint8') return x 9、定义模型并优化 '''定义VGG模型''' tf_session = K.get_session() cModel = VGG16(include_top=False, input_tensor=content_image_array) sModel = VGG16(include_top=False, input_tensor=style_image_array) gModel = VGG16(include_top=False, input_tensor=generate_image_placeholder) content_layer_name = 'block4_conv2' style_layer_names = [ 'block1_conv1', 'block2_conv1', 'block3_conv1', 'block4_conv1' ] '''得到对应的representation矩阵''' P = get_feature_represent(x=content_image_array, layer_names=[content_layer_name], model=cModel)[0] As = get_feature_represent(x=style_image_array, layer_names=style_layer_names, model=sModel) ws = np.ones(len(style_layer_names))/float(len(style_layer_names)) '''使用fmin_l_bfgs_b进行损失函数优化''' iterations = 600 x_val = generate_image.flatten() xopt, f_val, info = fmin_l_bfgs_b(func=calculate_loss, x0=x_val, fprime=get_grad, maxiter=iterations, disp=True) x_out = postprocess_array(xopt) 10、输出结果 初始化输出图片 迭代200次,${\beta \over \alpha} = 10^3$ 迭代500轮,${\beta \over \alpha} = 10^4$ 四、总结 style tranfer通过白噪声初始化(就是高斯分布)一个输出的结果,然后通过优化损失对这个结果进行风格和内容两方面的约束修正 图片的风格信息使用的是 Gram矩阵来表示 其中超参数风格损失的权重ws、内容损失和风格损失的权重$\alpha$, $\beta$可以进行调整查看结果 论文给出的${\beta \over \alpha} = 10^3或10^4$结果较好,可以自己适当增加看看最后的结果 Reference Paper: https://arxiv.org/pdf/1508.06576.pdf https://www.cs.toronto.edu/~frossard/post/vgg16/ https://zhuanlan.zhihu.com/p/339101382019-09-180 0 3072
-
之前有在阿里云GPU服务器上弄过: 点击查看, 这里从装Nvidia开始 一、 安装Nvidia驱动 1.1 查找需要安装的Nvidia版本 1.1.1 官网 官网上查找: https://www.nvidia.com/Download/index.aspx?lang=en-us 这里是 GeForce GTX 1080 TI 如下图,推荐 410 版本的 1.1.2 命令行查看推荐驱动 查看驱动:ubuntu-drivers devices, 如下图 ubuntu@ubuntu-System-Product-Name:~$ ubuntu-drivers devices == cpu-microcode.py == driver : intel-microcode - distro free == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 == vendor : NVIDIA Corporation modalias : pci:v000010DEd00001B06sv00001458sd0000374Dbc03sc00i00 driver : nvidia-410 - third-party free recommended driver : nvidia-384 - distro non-free driver : xserver-xorg-video-nouveau - distro free builtin driver : nvidia-390 - third-party free driver : nvidia-396 - third-party free - 注意这里添加了`ppa`, 若是没有,可能最新的只有`nvidia-384`, 但是若想安装`cuda-9.0` 需要大于`384.81`, 不然后面安装`tensorflow-gpu` 之后也会报错 - 图片对应网址:https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html ![cuda版本对应nvidia版本][4] - 添加 `ppa`: - `sudo add-apt-repository ppa:graphics-drivers/ppa` (注意联网,去掉代理) - `sudo apt update` - 然后执行`ubuntu-drivers devices`就可以看到如上的结果 - 安装: - 可能需要的依赖:`sudo apt install dkms build-essential linux-headers-generic` - 有些可能需要禁用`nouveau`模块,查看:https://blog.csdn.net/u012235003/article/details/54575758 - `sudo apt-get install linux-headers-$(uname -r)` - `sudo apt install nvidia-410` - 重启机器 - 查看: - `nvidia-smi` - 显示如下结果 ``` bash (wangyongzhi_ml) ubuntu@ubuntu-System-Product-Name:/usr/local/cuda-10.0/bin$ nvidia-smi Thu Oct 25 15:49:46 2018 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 410.66 Driver Version: 410.66 CUDA Version: 10.0 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 108... Off | 00000000:01:00.0 On | N/A | | 0% 44C P8 20W / 250W | 42MiB / 11174MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 108... Off | 00000000:02:00.0 Off | N/A | | 0% 50C P8 20W / 250W | 2MiB / 11178MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 949 G /usr/lib/xorg/Xorg 39MiB | +-----------------------------------------------------------------------------+ 跑个程序的使用情况 ubuntu@ubuntu-System-Product-Name:~$ nvidia-smi Thu Oct 25 21:20:00 2018 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 410.66 Driver Version: 410.66 CUDA Version: 10.0 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 108... Off | 00000000:01:00.0 On | N/A | | 0% 53C P2 128W / 250W | 10776MiB / 11174MiB | 44% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 108... Off | 00000000:02:00.0 Off | N/A | | 0% 52C P8 21W / 250W | 10631MiB / 11178MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 949 G /usr/lib/xorg/Xorg 39MiB | | 0 3009 C python 10725MiB | | 1 3009 C python 10619MiB | +-----------------------------------------------------------------------------+ 二、安装cuda 官网: https://developer.nvidia.com/cuda-toolkit-archive 选择想要安装的版本,这里选择的是cuda-9.0, 下载 安装 chmod +x cuda_9.0.176_384.81_linux-run sudo ./cuda_9.0.176_384.81_linux-run 根据提示安装选择即可 添加环境变量 vim ~/.bashrc 加入环境变量 # cuda9.0 export PATH=/usr/local/cuda-9.0/bin/:$PATH; export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64/:$LD_LIBRARY_PATH; 测试1 nvcc -V 如下图,版本为V9.0.176 (wangyongzhi_ml) ubuntu@ubuntu-System-Product-Name:~/wangyongzhi/software$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on Fri_Sep__1_21:08:03_CDT_2017 Cuda compilation tools, release 9.0, V9.0.176 测试2 如果上面安装过程中选择了安装Examples, 会在 ~ 文件夹下生成测试NVIDIA_CUDA-9.0_Samples 的文件 进入: cd NVIDIA_CUDA-9.0_Samples make 进入 NVIDIA_CUDA-9.0_Samples/bin/x86_64/linux/release 文件夹 执行: ./deviceQuery, 可以看到类似如下信息 ./deviceQuery Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 2 CUDA Capable device(s) Device 0: "GeForce GTX 1080 Ti" CUDA Driver Version / Runtime Version 10.0 / 9.0 CUDA Capability Major/Minor version number: 6.1 Total amount of global memory: 11174 MBytes (11717181440 bytes) (28) Multiprocessors, (128) CUDA Cores/MP: 3584 CUDA Cores GPU Max Clock rate: 1683 MHz (1.68 GHz) Memory Clock rate: 5505 Mhz Memory Bus Width: 352-bit L2 Cache Size: 2883584 bytes Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384) Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 2048 Maximum number of threads per block: 1024 三、安装cudnn 官网:https://developer.nvidia.com/rdp/cudnn-download 选择cuda对应的版本, 我的选择如下图 安装 tar -zxvf cudnn-9.0-linux-x64-v7.3.1.20.tgz 将解压得到的cuda 文件夹下的内容拷贝到对应的 /usr/local/cuda-9.0文件夹下即可 四、安装Anaconda和tensorflow-gpu 官网: https://www.anaconda.com/download/#linux 下载安装即可,我这里选择的是 python3.7 版本 安装之后添加到环境变量: # anaconda3 export PATH=/home/ubuntu/anaconda3/bin:$PATH 创建虚拟环境,防止污染他人使用环境 conda create -n xxx python-3.6 conda install tensorflow-gpu 测试 import tensorflow as tf sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 打印如下信息: 2018-10-25 16:25:35.683507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties: name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683 pciBusID: 0000:01:00.0 totalMemory: 10.91GiB freeMemory: 10.72GiB 2018-10-25 16:25:35.783459: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:897] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-10-25 16:25:35.783843: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 1 with properties: name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683 pciBusID: 0000:02:00.0 totalMemory: 10.92GiB freeMemory: 10.76GiB 2018-10-25 16:25:35.784321: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0, 1 2018-10-25 16:25:36.069610: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-10-25 16:25:36.069634: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0 1 2018-10-25 16:25:36.069637: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0: N Y 2018-10-25 16:25:36.069639: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 1: Y N 2018-10-25 16:25:36.069852: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10367 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1) 2018-10-25 16:25:36.101498: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10409 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1) Device mapping: /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1 /job:localhost/replica:0/task:0/device:GPU:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1 2018-10-25 16:25:36.134430: I tensorflow/core/common_runtime/direct_session.cc:288] Device mapping: /job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1 /job:localhost/replica:0/task:0/device:GPU:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1 五、 多个cuda版本切换 安装cuda-9.0 会在 /usr/local/ 目录下 如下图,它会创建一个软连接指向了 /usr/local/cuda-9.0/ (wangyongzhi_ml) ubuntu@ubuntu-System-Product-Name:/usr/local$ ll 总用量 48 drwxr-xr-x 12 root root 4096 10月 25 14:51 ./ drwxr-xr-x 13 root root 4096 10月 25 09:39 ../ drwxr-xr-x 2 root root 4096 4月 21 2016 bin/ lrwxrwxrwx 1 root root 19 10月 25 00:41 cuda -> /usr/local/cuda-9.0/ drwxr-xr-x 19 root root 4096 10月 25 14:52 cuda-10.0/ drwxr-xr-x 18 root root 4096 10月 25 00:41 cuda-9.0/ drwxr-xr-x 2 root root 4096 4月 21 2016 etc/ drwxr-xr-x 2 root root 4096 4月 21 2016 games/ drwxr-xr-x 2 root root 4096 4月 21 2016 include/ drwxr-xr-x 4 root root 4096 4月 21 2016 lib/ lrwxrwxrwx 1 root root 9 10月 24 14:52 man -> share/man/ drwxr-xr-x 2 root root 4096 4月 21 2016 sbin/ drwxr-xr-x 8 root root 4096 4月 21 2016 share/ drwxr-xr-x 2 root root 4096 4月 21 2016 src/ 所以正常安装cuda 其他版本,然后创建软连接指向对应的版本即可 sudo rm -rf cuda sudo ln -s /usr/local/cuda-10.0 /usr/local/cuda Reference https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html https://blog.csdn.net/u012235003/article/details/545757582019-09-180 0 3199

共4条