1 of 71

AI微課程-機械學習初步 �class 3 TWCC AI 計算�(AI微課程_1106)

李柏翰

leepohan@gmail.com

13 April, 2022

1

2022/4/13

2 of 71

2

2022/4/13

  1. 連上國網中心 NCHC 註冊帳號(台灣杉1號: 140.110.148.11),TWCC 計算簡介(台灣杉3號: ln01.twcc.ai)
  2. 利用 putty 連線,pscp 傳輸檔案
  3. Py37 conda環境設定
  4. TWCC 番茄AI辨識練習
  5. Google Colab 番茄AI辨識練習
  6. PC anaconda 番茄AI辨識練習

大綱

Lorenz Lab

3 of 71

3

2022/4/13

(一) NCHC註冊 (台灣杉1號)

Lorenz Lab

nchc.org.tw

4 of 71

4

2022/4/13

NCHC註冊 (台灣杉1號)

Lorenz Lab

5 of 71

5

2022/4/13

NCHC註冊 (台灣杉1號)

Lorenz Lab

6 of 71

6

2022/4/13

NCHC個人資料註冊

Lorenz Lab

7 of 71

7

2022/4/13

NCHC (主機帳號設定)

Lorenz Lab

8 of 71

8

2022/4/13

TWCC搜尋 (台灣杉3號)

Lorenz Lab

9 of 71

9

2022/4/13

TWCC (台灣杉3號)

Lorenz Lab

10 of 71

10

2022/4/13

TWCC (國網學研)

Lorenz Lab

11 of 71

11

2022/4/13

TWCC (容器選擇)

Lorenz Lab

12 of 71

12

2022/4/13

TWCC (開發環境)

Lorenz Lab

13 of 71

13

2022/4/13

TWCC (扣錢單位,1 GPU)

Lorenz Lab

14 of 71

14

2022/4/13

TWCC (建立容器)

Lorenz Lab

15 of 71

15

2022/4/13

TWCC (容器初始化)

Lorenz Lab

16 of 71

16

2022/4/13

不刪除每小時至少86元

有刪除掉才算數,關網頁沒用

Lorenz Lab

17 of 71

17

2022/4/13

TWCC : ln01.twcc.ai

Lorenz Lab

18 of 71

18

2022/4/13

TWCC : Jupyter

Lorenz Lab

19 of 71

19

2022/4/13

putty ; pscp; psftp下載

Lorenz Lab

20 of 71

20

2022/4/13

Copy these files to C:\Windows\

Lorenz Lab

21 of 71

21

2022/4/13

cmd 啟動 putty

Lorenz Lab

22 of 71

22

2022/4/13

putty : ln01.twcc.ai

Lorenz Lab

23 of 71

23

2022/4/13

連線 TWCC

主機帳號 🡺 密碼 🡺 MOTP 密碼

Lorenz Lab

24 of 71

24

2022/4/13

調整視窗字型大小

Lorenz Lab

25 of 71

25

2022/4/13

傳輸檔案

DOS folder 🡺 Linux

User> pscp –r folder phlee0514@140.110.148.11:/work1/phlee0514

Linux folder🡺 DOS

User> pscp –r phlee0514@140.110.148.11:/work1/phlee0514/folder .

Linux file🡺 DOS

User> pscp phlee0514@140.110.148.11:/work1/phlee0514/folder/file .

Lorenz Lab

26 of 71

26

2022/4/13

Lorenz Lab

>>用conda建立及管理python虛擬環境

# 清除 module 確保環境乾淨

$ module purge

# 載入 Conda 環境,以預設 python3 的 miniconda3 為範例

$ module load miniconda3

# 由於 TWCC 設計的 miniconda module,會自動初始化環境變數,不需要再 conda init。

# 建議移除之前 conda init 產生的內容

$ conda init --reverse

# 之後再 set env py37

進入 TWCC 之後, load miniconda3

27 of 71

27

2022/4/13

Lorenz Lab

2-1. TWCC 安裝Tf=1.x環境

>> conda –V (查版本)�>> conda env list (查幾種環境)�>> conda update conda (更新conda)�>> conda create --name py37 python=3.7 (建立環境)�>> conda activate py37 (啟動環境)

>>pip install tensorflow==1.15

>>pip install keras==2.3.1 (此次 intel 範例 python == 3.7)

>>pip install notebook�>> conda install –c anaconda ipykernel (加入jupyter)�>> python –m ipykernel install --user --name=py37

>> conda install scikit-learn

>> pip install opencv-python

# 用container 啟動 jupyter�

28 of 71

28

2022/4/13

Lorenz Lab

2-2. TWCC 安裝 Tf=2.x 環境

>> conda env list (查幾種環境)�>> conda create --name py38 python=3.8 (建立環境)�>> conda activate py38 (啟動環境)

>>pip install tensorflow==2.4.0

>>pip install matplotlib==3.5.1

>>pip install opencv-python==4.5.5.62

>>pip install opencv-python-headless==4.5.5.62

>>pip install sklearn==0.0

>>pip install notebook�>> conda install –c anaconda ipykernel (加入jupyter)�>> python –m ipykernel install --user --name=py38

# 用container 啟動 jupyter

29 of 71

29

2022/4/13

使用 TWCC & PC 傳輸檔案

30 of 71

30

2022/4/13

使用 TWCC jupyter notebook

31 of 71

31

2022/4/13

使用 TWCC jupyter notebook

32 of 71

32

2022/4/13

33 of 71

33

2022/4/13

34 of 71

34

2022/4/13

35 of 71

35

2022/4/13

36 of 71

36

2022/4/13

37 of 71

37

2022/4/13

38 of 71

38

2022/4/13

39 of 71

39

2022/4/13

40 of 71

40

2022/4/13

41 of 71

41

2022/4/13

42 of 71

42

2022/4/13

43 of 71

43

2022/4/13

Loss and accuracy

44 of 71

44

2022/4/13

使用 TWCC jupyter notebook

45 of 71

45

2022/4/13

5.使用 Google Colaboratory

番茄AI辨識練習

46 of 71

46

2022/4/13

47 of 71

47

2022/4/13

使用 Google Colaboratory

48 of 71

48

2022/4/13

上傳 tomato.zip

49 of 71

49

2022/4/13

6.使用 Anaconda番茄AI辨識練習

50 of 71

50

2022/4/13

51 of 71

51

2022/4/13

52 of 71

52

2022/4/13

7. Python 語法練習

53 of 71

53

2022/4/13

##1-1.and or 運算子

a,b,c=5,10,6

result1= a>b and b>c #and運算

result2= a<b or c!=a #or運算

print(result1) ; print(result2) #輸出結果

False

True

1-1.py 邏輯運算子

54 of 71

54

2022/4/13

##1-2.py

score =50

if(score >=60):

print("Pass") # if 的語法需要將程序往後空格

else:

print("Fail")

Fail

1-2.py if結構

55 of 71

55

2022/4/13

##1-3.py

total=0

for count in range(1,101):

total+=count

print("1加到100=",total)

 

1加到100= 5050

56 of 71

56

2022/4/13

##1-4.py

total=0

for count in range(1,100,2):

total+=count

print("1~100奇數和=",total)

1~100奇數和= 2500

 

57 of 71

57

2022/4/13

##1-5.py

x,y=1,10

while x<y:

x+=1

print(x)

10

1-5.py while迴圈

58 of 71

58

2022/4/13

##1-6.py

total=0

for i in range(1, 201, 2):

if i==101:

break # 跳脫迴圈

total+=i

print("1~100奇數和",total)

1-6.py break指令

1~100奇數和 2500

59 of 71

59

2022/4/13

##1-7.py

for x in range(1,10):

if x==5:

continue # 跳脫本輪迴圈

print(x,end="")

1 2 3 4 6 7 8 9

1-7.py continue指令

60 of 71

60

2022/4/13

##1-8.py

List1=["A","B","C","D","E"]

for i in range(len(List1)):

print(List1[i])

A

B

C

D

E

1-8.py list結構

61 of 71

61

2022/4/13

##1-9.py

a=[3,8,4] )# a=[ ] 陣列

print(max(a)) # 印出最大

a.sort() # 排序

print(a) # 印出a

8

[3, 4, 8]

1-9.py 挑最大數字

62 of 71

62

2022/4/13

##1-10.py

a=[3,8,4] # a=[ ] 陣列

print(min(a)) # 印出最小

a.sort() # 排序

print(a) # 印出a

3

[3, 4, 8]

1-10.py 挑最小數字

63 of 71

63

2022/4/13

##1-11.py

word1= "zoo"

word2="animal"

print("交換前:",word1,word2)

word2,word1 = word1,word2 #Unpacking

print("交換後:",word1,word2)

交換前:zoo animal

交換後:animal zoo

1-11.py Unpacking

64 of 71

64

2022/4/13

##1-12.py

def func(a,b,c):

x=a+b+c

print(x)

print(func(1,2,3))

6

None

1-12.py 函數

65 of 71

65

2022/4/13

##1-13.py

L1=[1,3,5,7]

T1=tuple(L1)

print(T1)

(1,3,5,7) # 注意:小括號表示型態為元組

1-13.py 元組

66 of 71

66

2022/4/13

##1-14.py

Index="Hello Python, This is Program"

print("Index字串:",Index)

print(Index[3])

Index字串: Hello Python, This is Program

l

1-14.py 切割字串

67 of 71

67

2022/4/13

##1-15.py

def pow(x,y):

p=1;

for i in range(y):

p*=x

return p

x,y=2,10

print(pow(x,y))

1-15.py 建立函式,解2的10次方

1024

68 of 71

68

2022/4/13

## 27.py

import random

target=random.randrange(1,100)

print("請猜個數字,在1到100之間")

guess=0

num=1

while guess!=target:

print("第",num,"次猜")

guess=int(input("請猜:"))

if guess>target:

print("太大了")

elif guess<target:

print("太小了")

else:

print("猜中")

print("=======================")

num+=1

27.Py 請猜個數字,在1到100之間

69 of 71

69

2022/4/13

第 1 次猜請猜:50太大了===============================

第 2 次猜請猜:2太小了

===============================

第 3 次猜請猜:40太大了

…..

第 10 次猜請猜:12猜中

===============================

27.Py 答案: 請猜個數字,在1到100之間

70 of 71

70

2022/4/13

## 2-2.py

# -*- coding: utf-8 -*-

def fib(n):

if (n == 1 or n == 2):

return 1

else:

return (fib(n - 1) + fib(n - 2))

i = int(input("請輸入欲顯示到第幾個費波南希係數:"))

for x in range(1, i + 1):

print(f"\t{fib(x)}", end = "")

2-2.py 建立函式,費波南希係數

到第幾個費波南希係數:7

1 1 2 3 5 8 13

71 of 71

71

2022/4/13

Thanks for attention

Lorenz Lab