华为人工智能培训

Lesson1

ftp的连接:

ssh -p 22 root@114.116.156.117
密码:yuanxin_120


image.png

uci查看数据集

Lesson1 作业反馈

汽车数据

####################################
########## Make car data ###########
####################################

import numpy as np

def make_data(data_path):
   data_x = []
   data_y = []
   with open(data_path,'r') as file:
       datas = file.readlines()
   for line_num in range(len(datas)):
       data_x.append(datas[line_num].split(',')[:-1]) #取从一开始一直到倒数第二个的所有切片
       data_y.append(datas[line_num].split(',')[-1].split('\n')[0])
#换行取第一行 相当于在这个(vhigh,vhigh,2,2,small,low,unacc/n)里面先用,切割然后留下unacc/n再去切割/n
       for x_num in range(len(data_x[0])):
           data_x[line_num][x_num] = feature_list[x_num].index(data_x[line_num][x_num])
           data_y[line_num] = label_list.index(data_y[line_num]) 
#index是用于识别指定元素的位置号的 a=[2,15] a.index(15)返回15的位置1
   print(data_x)
   print(np.array(data_x))
   return np.array(data_x), np.array(data_y)
   
if __name__=='__main__':
#_name__ 是当前模块名,当模块被直接运行时模块名为 __main__ 。
#这句话的意思就是,当模块被直接运行时,以下代码块将被运行
#,当模块是被导入时,代码块不被运行。
   data_path = 'data/car.data'
   feature_list = [['vhigh', 'high', 'med', 'low'],
                   ['vhigh', 'high', 'med', 'low'],
                   ['2', '3', '4', '5more'],
                   ['2', '4', 'more'],
                   ['small', 'med', 'big'],
                   ['low', 'med', 'high']]
   label_list = ['unacc','acc','good','vgood']
   X, Y  = make_data(data_path)
   Z=[]
   for i in range(len(X)):
       print(X[i]+Y[i])

机器人

注意实例化的方式直接就是a=main()
然后就可以a.各种方法
因此也需要在类里面去写那种main函数

######################################
#### 实验:逻辑小机器人  o(O_O)o  ####
######################################

import numpy as np

def create_map(map_lenth, table_lenth):
    # 建立地图函数
    map = np.zeros((map_lenth,map_lenth))
    map[0:table_lenth , 0:table_lenth] = 1
    map[(map_lenth-table_lenth):map_lenth , 0:table_lenth] = 1
    map[0:table_lenth ,(map_lenth-table_lenth):map_lenth] = 1
    map[(map_lenth-table_lenth):map_lenth , (map_lenth-table_lenth):map_lenth] = 1
    return map

def service_list(game):
    # 游戏清单函数
    locA = (2,2)
    locB = (10,2)
    locC = (2,10)
    locD = (10,10)
    locE = (12,6)
    return locA,locB,locC,locD,locE
    
# Todo: 根据你自己的构思,完成每个游戏的内容 #
# ---------------------------------------------#

def load_gameA():

    sentence = input("\nClassic dialogue: ")
    if sentence == "The Gods envy us.":
        print("\nThey envy us because we're mortal, because any moment may be our last.")
        print("Everything is more beautiful because we're doomed.\n")
    else:
        print("Sorry, I don't know this. \n")
        
def load_gameB():
    pass
    
def load_gameC():
    pass
    
def load_gameD():
    pass
    
# ----------------------------------------------#
    
    
class robot():
    
    def __init__(self, name, map_lenth, table_lenth, game):
        # 存放机器人名字
        self.name = name
        # 存放游戏列表
        self.game = game
        # 存放地图
        self.robot_map = create_map(map_lenth, table_lenth)
        # 存放机器人的位置
        self.local = (int(map_lenth/2) , int(map_lenth/2))
        # 初始化机器人位置在中心
        self.robot_map[self.local] = 2
        locA,locB,locC,locD,locE = service_list(game)
        self.memory = {'A':locA, 'B':locB, 'C':locC, 'D':locD, 'E':locE}
        self.message = ""
        print(self.robot_map)
        print("\nRobot {} is ready. ".format(self.name))
        
    def localization(self):
        # 机器人定位,查看当前机器人的位置
        location = np.where(self.robot_map == 2)
        robot_x = location[0][0]
        robot_y = location[1][0]
        return (robot_x, robot_y)
    
    def sensor(self, robot_local, aim_point):
        # 机器人向目标测距
        robot_path_x = (min(robot_local[0], aim_point[0]), max(robot_local[0], aim_point[0]))
        robot_path_y = (min(robot_local[1], aim_point[1]), max(robot_local[1], aim_point[1]))
        print("\nMeasurement results have been obtained")
        return (robot_path_x, robot_path_y)
    
    def move(self, robot_path, aim_point):
        # 清理地图
        self.robot_map = create_map(map_lenth, table_lenth)
        # 机器人行动逻辑
        x, y = robot_path[0], robot_path[1]
        print("\nGoing to the target point ({},{})".format(aim_point[0],aim_point[1]))
        ## 当前位置写为0
        self.robot_map[self.local] = 0
        ## 沿 Y 轴纵移
        if y[0] == self.local[1]:
            self.robot_map[x[0]:x[1]+1 , y[0]] = 1
        else:
            self.robot_map[x[0]:x[1]+1 , y[1]] = 1
        ## 沿 X 轴横移
        if x[0] == self.local[1]:
            self.robot_map[x[1] , y[0]:y[1]+1] = 1
        else:
            self.robot_map[x[0] , y[0]:y[1]+1] = 1
        ## 目标位置写为2
        self.robot_map[aim_point] = 2
        print("\nPosition calculation completed, Robot {} is moving".format(self.name))
        print(self.robot_map)
        
    def go_back(self):
        self.robot_map = create_map(map_lenth, table_lenth)
        self.local = (int(map_lenth/2) , int(map_lenth/2))
        self.robot_map[self.local] = 2
        print("\nRobot {} has returned to its original position.\n".format(self.name))
        print(self.robot_map)
    def send_service(self):
        print("A: {}\n".format(self.game[0]))
        print("B: {}\n".format(self.game[1]))
        print("C: {}\n".format(self.game[2]))
        print("D: {}\n".format(self.game[3]))
        game_choice = input("Which game do you like? Choice A, B, C, D:  ")
        return game_choice
    
    def think(self, game_choice):
        robot_local = self.localization()
        robot_path = self.sensor(robot_local, self.memory[game_choice])
        self.move(robot_path, self.memory[game_choice])
        if game_choice == 'E':
            print("\nHi Boss!")
            print("\nI am here for service! Please select the interactive game you want to play, just enter one letter (A,B,C,D): ")
        elif game_choice == 'A':
            load_gameA()
        elif game_choice == 'B':
            load_gameB()
        elif game_choice == 'C':
            load_gameC()
        elif game_choice == 'D':
            load_gameD()
        else:
            pass

            
name = 'HUAWEI'
map_lenth = 13
table_lenth = 2
game  = ["GAME_A", "GAME_B","GAME_C","GAME_D","Hi"]

def main(name=name, map_lenth=map_lenth, table_lenth=table_lenth, game=game):
    my_robot = robot(name, map_lenth, table_lenth, game)
    Flag = True
    # 第一声问候
    while Flag:
        my_robot.message = input("Hello please say hi to me: ")
        if my_robot.message == 'hi':
            my_robot.think('E')
            game_choice = 0
            while Flag:
                game_choice = my_robot.send_service()
                if game_choice not in ['A','B','C','D']:
                    game_choice = print("The command you entered is incorrect, please re-enter. \n")
                else:
                    Flag = False
        else:
            print("Please enter the correct order(hi): ")
       
    # 玩游戏
    my_robot.think(game_choice)
    my_robot.go_back()
    print("\nBye!\n")

a=main()


## --------------------------------M(O_O)M-------------------------------- ##
## 实例化主程序以启动机器人                                                ##
## main(name, map_lenth, table_lenth, game)                                ##
## name: 机器人名字(默认 HUAWEI)                                         ##
## map_lenth: 地图尺寸(默认13)                                           ##
## table_lenth: 操作台尺寸(默认2)                                        ##
## game: 游戏列表(默认["GAME_A", "GAME_B","GAME_C","GAME_D","Hi"])       ##
## --------------------------------M(O_O)M-------------------------------- ## 

感知器

np.linspace(2.0, 3.0, num=5)
    (array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]))
2-3之间切出来5个数字

图书管理员

print("Your card ID is {}".format(user_id)) #在{}填充userid

Lesson4

keras放模型的位置:(参考day4 Art的model )

ls -a
cd .keras/
cp /Users/yuanxin/Desktop/Art/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5 ./models/

cp是把model拷贝进去
![image.png](https://upload-images.jianshu.io/upload_images/1954308-ffa4510631699592.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

GPU跑代码

yuanxindeMacBook-Pro:~ yuanxin$ ssh it_stu107@sjtu-ai.simplehpc.com
it_stu107@sjtu-ai.simplehpc.com's password: 

[it_stu107@head2 ~]$ module load anaconda2/5.3.0
[it_stu107@head2 ~]$ conda create -n peter2
(peter) [it_stu107@head2 ~]$ source activate peter2
(peter2) [it_stu107@head2 ~]$ conda install -c kehang keras
(peter2) [it_stu107@head2 ~]$ conda install matplotlib


##一些基本操作
(peter2) [it_stu107@head2 ~]$ ll
总用量 3
-rw-rw-r-- 1 it_stu107 it_stu107 243 12月  8 19:14 cnnrun.sh
drwxr-xr-x 6 it_stu107 it_stu107  29 12月  8 19:13 DenseNet-Cifar10-master
-rw-rw-r-- 1 it_stu107 it_stu107  73 12月  8 19:13 log.1905.err
-rw-rw-r-- 1 it_stu107 it_stu107   0 12月  8 19:11 log.1905.out
-rw-rw-r-- 1 it_stu107 it_stu107 118 12月  8 19:14 log.1908.err
-rw-rw-r-- 1 it_stu107 it_stu107   0 12月  8 19:14 log.1908.out
drwxr-xr-x 2 it_stu107 it_stu107   1 12月  8 18:45 tensor
(peter2) [it_stu107@head2 ~]$ vi log.1908.err

##最好把cnnrun.sh挪到放代码的文件夹,这样log就是在这个文件夹内,不会到主页来
(peter2) [it_stu107@head2 ~]$ mv cnnrun.sh tensor/

##删除之前一些log
(peter2) [it_stu107@head2 ~]$ rm log.190*

##显示文件
(peter2) [it_stu107@head2 ~]$ ll

总用量 1
drwxr-xr-x 6 it_stu107 it_stu107 29 12月  8 19:13 DenseNet-Cifar10-master
drwxr-xr-x 2 it_stu107 it_stu107  2 12月  8 19:16 tensor
(peter2) [it_stu107@head2 ~]$ cd tensor
(peter2) [it_stu107@head2 tensor]$ ll
总用量 5
-rw-rw-r-- 1 it_stu107 it_stu107  243 12月  8 19:14 cnnrun.sh
-rw-r--r-- 1 it_stu107 it_stu107 4517 12月  8 18:45 tensor.py
##跑代码的脚本
(peter2) [it_stu107@head2 tensor]$ vim cnnrun.sh
##运行
(peter2) [it_stu107@head2 tensor]$ sbatch cnnrun.sh
Submitted batch job 1910
##查看进度
(peter2) [it_stu107@head2 tensor]$ sq

##mac与linux传文件(注意是直接在终端传不用进到gpu传送)
###传到当前目录
scp /home/daisy/full.tar.gz root@172.19.2.75:~
###传整个文件夹
scp -r /home/daisy/full.tar.gz root@172.19.2.75:~
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容