Lesson1
ftp的连接:
ssh -p 22 root@114.116.156.117
密码:yuanxin_120
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:~