欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于win10在tensorflow的安裝及在pycharm中運(yùn)行步驟詳解

 更新時(shí)間:2020年03月16日 14:50:50   作者:星空比上  
這篇文章主要介紹了關(guān)于win10在tensorflow的安裝及在pycharm中運(yùn)行的步驟詳解,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

本文介紹在win10中安裝tensorflow的步驟:

1、安裝anaconda3

2、新建conda環(huán)境變量,可建多個(gè)環(huán)境在內(nèi)部安裝多個(gè)tensorflow版本,1.x和2.x版本功能差別太大,代碼也很大區(qū)別

3、環(huán)境中安裝python和fensorflow

4、用tensorflow運(yùn)行一段測(cè)試程序

安裝anaconda下載地址(清華鏡像):

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/選擇最新版本

在這里插入圖片描述

開(kāi)始安裝anaconda

在這里插入圖片描述在這里插入圖片描述在這里插入圖片描述

選擇安裝位置

在這里插入圖片描述

勾選后,點(diǎn)擊 install

在這里插入圖片描述

等待一段時(shí)間

在這里插入圖片描述

安裝完成,直接退出

在這里插入圖片描述 在這里插入圖片描述 在這里插入圖片描述

安裝好anaconda以后,打開(kāi)cmd輸入conda --version” ----->得到conda 4.7.12,安裝成功

在這里插入圖片描述

anaconda3就安裝好了

開(kāi)始安裝tensorflow

國(guó)外原地址下載太慢,這里設(shè)置國(guó)內(nèi)鏡像源,否則特別慢。。。。:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/    

conda config --set show_channel_urls yes

在這里插入圖片描述 查看Python版本

我們先安裝tensorflow2.0版本創(chuàng)建新的環(huán)境tensorflow2,輸入: conda create -n tensorflow2 python=3.7

在這里插入圖片描述

輸入 y

開(kāi)始自動(dòng)下載文件(可以看到下載的Python版本為3.7.6版本,文件目錄在E:\anaconda3\envs中,后面配置時(shí)會(huì)用到),

在這里插入圖片描述

激活剛才創(chuàng)建的環(huán)境,輸入 : activate tensorflow2

在這里插入圖片描述

然后就開(kāi)始安裝TensorFlow,輸入: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.0.0-beta1

在這里插入圖片描述

接下來(lái)自動(dòng)安裝好了,出現(xiàn)下面提示就安裝好了,哈哈!

在這里插入圖片描述

python的版本不一樣,運(yùn)行環(huán)境也不一樣,如果還要安裝1.x版本,(這里安裝tensorflow1.9.0版本),再次進(jìn)入cmd中

創(chuàng)建新的1.x版本環(huán)境

輸入 :conda create -n tensorflow1 python=3.6 激活新環(huán)境

輸入 : activate tensorflow1 安裝TensorFlow

輸入: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.9.0

在這里插入圖片描述

安裝過(guò)程中,如需pip9.0.1升級(jí)pip20:

輸入 python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

運(yùn)行tensorflow

既然fensorflow安裝好了,我現(xiàn)在用pycharm打開(kāi)運(yùn)行一段代碼,首先配置pycharm

在這里插入圖片描述

打開(kāi)設(shè)置–項(xiàng)目–項(xiàng)目編輯器–點(diǎn)擊Add

在這里插入圖片描述

按下面步驟,設(shè)置環(huán)境就ok了

(https://img-

我們?cè)O(shè)置一個(gè)新環(huán)境,將環(huán)境再改為剛安裝好的tensorflow1.9.0的版本,測(cè)試運(yùn)行一個(gè)小程序。

# -*- coding: utf-8 -*-
"""
Created on Mon Nov 19 19:33:03 2018
@author: KUMA
"""
import numpy as np
import tensorflow as tf
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
class LinearSep:
 def __init__(self):
 self.n_train = 10
 self.n_test = 50
 self.x_train, self.y_train, self.x_test, self.y_test = self._gene_data()
 def _gene_data(self):
 x = np.random.uniform(-1, 1, [self.n_train, 2])
 y = (x[:, 1] > x[:, 0]).astype(np.int32)
 x += np.random.randn(self.n_train, 2) * 0.05
 x_test = np.random.uniform(-1, 1, [self.n_test, 2])
 y_test = (x_test[:, 1] > x_test[:, 0]).astype(np.int32)
 return x, y, x_test, y_test
# 隨機(jī)生成數(shù)據(jù)
dataset = LinearSep()
X_train, Y_train = dataset.x_train, dataset.y_train
print(Y_train)
Y_train = np.eye(2)[Y_train]
X_test, Y_test = dataset.x_test, dataset.y_test
Y_test = np.eye(2)[Y_test]
x = tf.placeholder(tf.float32, [None, 2], name='input')
y = tf.placeholder(tf.float32, [None, 2], name='output')
w1 = tf.get_variable(name='w_fc1', shape=[2, 20], dtype=tf.float32)
b1 = tf.get_variable(name='b_fc1', shape=[20], dtype=tf.float32)
out = tf.matmul(x, w1) + b1
out = tf.nn.relu(out)
w2 = tf.get_variable(name='w_fc2', shape=[20, 2], dtype=tf.float32)
b2 = tf.get_variable(name='b_fc2', shape=[2], dtype=tf.float32)
out = tf.matmul(out, w2) + b2
out = tf.nn.softmax(out)
# cross entropy 損失函數(shù)
loss = -tf.reduce_mean(tf.reduce_sum(y * tf.log(out + 1e-8), axis=1), axis=0)
# 準(zhǔn)確率
correct_pred = tf.equal(tf.argmax(y, axis=1), tf.argmax(out, axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
# 定義優(yōu)化器
train_op = tf.train.AdamOptimizer(1e-3).minimize(loss) # 1e-3 是學(xué)習(xí)律
# 初始化網(wǎng)絡(luò)
# BATCH_SIZE = 128
EPOCH = 7000 # 優(yōu)化次數(shù)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for ep in range(EPOCH):
 sess.run(train_op, feed_dict={x: X_train, y: Y_train})
 loss_train, acc_train = sess.run([loss, accuracy], feed_dict={x: X_train, y: Y_train})
 acc_test, pre_test = sess.run([accuracy, correct_pred], feed_dict={x: X_test, y: Y_test})
 if ep % 1000 == 0:
 print(ep, loss_train, acc_train, acc_test)
 print(Y_test.shape)
test_pre = sess.run(out, feed_dict={x: X_test, y: Y_test})
print(len(test_pre))
mask = np.argmax(test_pre, axis=1)
print(mask)
mask_0 = np.where(mask == 0)
mask_1 = np.where(mask == 1)
X_0 = X_train[mask_0]
X_1 = X_train[mask_1]
print(X_0)

結(jié)果如下:

`[1 0 1 0 1 1 1 0 1 1] T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

0 0.81077516 0.1 0.34 (50, 2) 1000 0.013808459 1.0 0.82 (50, 2) 2000 0.0025899492 1.0 0.82 (50, 2) 3000 0.00088921207 1.0 0.82 (50, 2) 4000 0.00038405406 1.0 0.82 (50, 2) 5000 0.0001859894 1.0 0.82 (50, 2) 6000 8.420033e-05 1.0 0.82 (50, 2) 50 [0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 0 1 1 0 1 1 1]`

其中出現(xiàn) Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 這個(gè)沒(méi)問(wèn)題,可以忽略,能正常運(yùn)行出結(jié)果。

總結(jié)

到此這篇關(guān)于關(guān)于win10在tensorflow的安裝及在pycharm中運(yùn)行步驟詳解的文章就介紹到這了,更多相關(guān)tensorflow安裝pycharm運(yùn)行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python中Matplotlib繪圖保存圖片時(shí)調(diào)節(jié)圖形清晰度或分辨率的方法

    Python中Matplotlib繪圖保存圖片時(shí)調(diào)節(jié)圖形清晰度或分辨率的方法

    有時(shí)我們?cè)谑褂胢atplotlib作圖時(shí),圖片不清晰或者圖片大小不是我們想要的,這篇文章主要給大家介紹了關(guān)于Python中Matplotlib繪圖保存圖片時(shí)調(diào)節(jié)圖形清晰度或分辨率的相關(guān)資料,需要的朋友可以參考下
    2024-05-05
  • Python中利用all()來(lái)優(yōu)化減少判斷的實(shí)例分析

    Python中利用all()來(lái)優(yōu)化減少判斷的實(shí)例分析

    在本篇文章里小編給大家整理的是一篇關(guān)于Python中利用all()來(lái)優(yōu)化減少判斷的實(shí)例分析內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2021-06-06
  • Python制作摩斯密碼翻譯器

    Python制作摩斯密碼翻譯器

    摩斯密碼是一種將文本信息作為一系列通斷的音調(diào)、燈光或咔嗒聲傳輸?shù)姆椒ǎ疚膶⒔榻B如何通過(guò)Python制作摩斯密碼翻譯器,感興趣的童鞋可以關(guān)注一下
    2021-11-11
  • pandas中NaN缺失值的處理方法

    pandas中NaN缺失值的處理方法

    當(dāng)我們用python進(jìn)行數(shù)據(jù)處理時(shí)會(huì)遇到很多缺失值,對(duì)缺失值我們需要進(jìn)行刪除或者填補(bǔ),本文主要介紹了pandas中NaN缺失值的處理方法,感興趣的可以了解一下
    2021-05-05
  • Python使用Pandas生成日?qǐng)?bào)的實(shí)現(xiàn)代碼

    Python使用Pandas生成日?qǐng)?bào)的實(shí)現(xiàn)代碼

    Pandas是Python中一個(gè)強(qiáng)大的數(shù)據(jù)處理庫(kù),它提供了許多功能強(qiáng)大的數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)分析工具,在本文中,我們將介紹Pandas的基本概念和如何使用它生成一個(gè)包含今天到未來(lái)20個(gè)工作日的日期列表的Excel文件,需要的朋友可以參考下
    2023-11-11
  • Pytorch建模過(guò)程中的DataLoader與Dataset示例詳解

    Pytorch建模過(guò)程中的DataLoader與Dataset示例詳解

    這篇文章主要介紹了Pytorch建模過(guò)程中的DataLoader與Dataset,同時(shí)PyTorch針對(duì)不同的專業(yè)領(lǐng)域,也提供有不同的模塊,例如?TorchText,?TorchVision,?TorchAudio,這些模塊中也都包含一些真實(shí)數(shù)據(jù)集示例,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2023-01-01
  • 最新評(píng)論