Compare commits

..

10 Commits

@ -0,0 +1,14 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
class Arc:
def __init__(self, argv):
self.id = int(argv[0])
self.from_node = int(argv[1])
self.to_node = int(argv[2])
self.len = float(argv[3])
self.road_class = argv[4]
self.geometry_list = [float(ele) for ele in argv[5:9]]
self.direction = float(argv[9])

@ -0,0 +1,10 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
class ArcMany:
def __init__(self, argv2):
self.geometry_list2 = [float(ele) for ele in argv2[0:2]]
self.id = int(argv2[2])

@ -0,0 +1,11 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
class CarPath:
def __init__(self, argv4):
self.path = int(argv4[0])
self.id = int(argv4[1])
self.time_stage = int(argv4[2])

@ -0,0 +1,3 @@
class CarQuery:
def __init__(self, argv):
self.geo = [float(ele) for ele in argv[0:2]]

@ -0,0 +1,10 @@
class CarRecord:
def __init__(self, argv):
self.car = int(argv[0])
self.car_id = int(argv[10])
self.time = argv[1]
self.geo = [float(ele) for ele in argv[2:4]]
self.hight = float(argv[4])
self.speed = float(argv[5])
self.direction = float(argv[6])
self.id = int(argv[8])

@ -0,0 +1,88 @@
from idlelib import tooltip
from math import *
import queue
import sys
import time
import os
from datetime import datetime
import pymssql
import pandas as pd
import numpy as np
import datetime
import math
from folium import plugins
import folium
import os
sys.path.append(r'C:\Users\Wayson\Desktop')
from CarQuery import *
from Arc import *
from ArcMany import *
arc_objects=[]
Arc_many_count=[]
Arc_many_objects=[]
Arc_data2=[]
# 返回两个gps点的实际距离x,y与米的换算约为1:111000。不同的比例尺换算不一样
def DistanceActual(geo1, geo2):
return pow(pow(float(geo1[0]) - float(geo2[0]), 2) + pow(float(geo1[1]) - float(geo2[1]), 2), 0.5) * 111000
# 如果起点定位数据跟道路的相差很远则没有必要取该条arc
def CheckNecessary(arc, car_record):
if DistanceActual(arc.geometry_list[0], car_record.geo) > 1000:
if DistanceActual(arc.geometry_list[-1], car_record.geo) > 1000:
return False
else:
return True
def CalCost(arc, car_record):
cost = float("inf")
# CheckNecessary函数首先排除与起点定位点距离相差远的路段。/LOU
if CheckNecessary(arc, car_record):
# 下面if是计算这条道路上所有点跟目标点的最短距离小于10m才返回True。我们认为起点定位精度为10m
min_dist = float("inf")
for geo1 in arc.geometry_list:
tmp = DistanceActual(geo1, car_record.geo)
if tmp < min_dist:
min_dist = tmp
cost = min_dist
return cost
# 给定car_geo和car_direction根据最短距离计算在所有道路的Cost返回Cost最小的道路id
def CalMinCostArcID(car_record):
min_cost = float("inf")
id = 0
# arc_objects存储着所有边的Arc对象实例即所有路段信息。/LOU
for arc in arc_objects:
cost = CalCost(arc, car_record)
if cost < min_cost:
min_cost = cost
id = arc.id
return id
# 得到id为i的路段的密集点集合
def ArcmanyRecordsDivide(Arcmany_i):
Arcmany_index_start = sum(Arc_many_count[:Arcmany_i]) # 第i路段的起始索引位置
Arcmany_index_end = sum(Arc_many_count[:Arcmany_i + 1]) # 第i路段的终止索引位置
Arcmany_record_list = Arc_many_objects[Arcmany_index_start: Arcmany_index_end] # 每个路段的点集合
Arcmany_geo_list = [Arcmany_record.geometry_list2 for Arcmany_record in Arcmany_record_list] # 每个路段的点的(x,y)集合
return Arcmany_geo_list
def swap_loc(list):
temp = 0
for i in range(0,len(list)):
temp = list[i][1]
list[i][1] = list[i][0]
list[i][0] = temp
# arc_objects里的路段经纬度更新为点集合
for i in range(0, len(Arc_data2)): # 对每条路段循环
del arc_objects[i].geometry_list[0:4] # 删除第i条路段原有的(x,y)信息
Arcmany_record_list_i = ArcmanyRecordsDivide(i) # 提取第i条路段新的密集点(x,y)信息
for j in range(0, len(Arcmany_record_list_i)): # 对第i条路段新的密集点(x,y)信息循环
arc_objects[i].geometry_list.append(Arcmany_record_list_i[j]) # 在第i条路段(x,y)列加上 新的密集点(x,y)第j条信息

@ -0,0 +1,313 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from math import *
import queue
import sys
import time
import os
from datetime import datetime
import pymssql
import pandas as pd
import numpy as np
import datetime
import math
sys.path.append(r'C:\Users\Administrator\Desktop')
from CarRecord import *
from Arc import *
from ArcMany import *
from CarPath import *
arc_objects=[]
map_graph=[]
car_id_count=[]
#通过经纬度计算两点之间的距离
def DistanceBetween(geo1, geo2):
return pow(pow(float(geo1[0]) - float(geo2[0]), 2) + pow(float(geo1[1]) - float(geo2[1]), 2), 0.5)
# 知道三个顶点坐标ABC看角ACB是否是锐角三角形
def CheckOxygon(A, C, B):
a = DistanceBetween(C, B)
b = DistanceBetween(A, C)
c = DistanceBetween(A, B)
if a ** 2 + b ** 2 < c ** 2:
return False
else:
return True
# 计算起点到终点线段方向与x轴的夹角 逆时针
# geo_list 第一个参数-1终点 0起点 第二个参数 0--y 1--x
def CalDirection(geo_list):
if geo_list[-1][0] == geo_list[0][0]:
if geo_list[-1][1] > geo_list[0][1]:
return float(0)
else:
return float(180)
else:
# tan=slope
# arctan(tan x)=x
slope = (geo_list[-1][1] - geo_list[0][1]) / (geo_list[-1][0] - geo_list[0][0])
if geo_list[-1][0] > geo_list[0][0]: # 如果射线在第1,2象限
return 90 - (atan(slope) / pi * 180) # 由于角度是跟x轴的夹角所以需要90-
else: # 如果射线在第3,4象限
return 90 - (atan(slope) / pi * 180) + 180
# 传入geo1, geo2为直线y = kx + d上两点求geo3在直线上的射影即作垂直后与直线的交点
# 如果形成钝角三角形则垂点取geo1geo2中靠近geo3的那个 就是直接过去
def CalProjection(geo1, geo2, geo3):
geo1 = [float(ele) for ele in geo1]
geo2 = [float(ele) for ele in geo2]
geo3 = [float(ele) for ele in geo3]
a = DistanceBetween(geo2, geo3)
b = DistanceBetween(geo1, geo3)
c = DistanceBetween(geo1, geo2)
if (a**2 + c**2) <= b**2: #钝角三角形且geo3靠近geo2包括点在线段延长线上的情况
return geo2
elif b**2 + c**2 <= a**2: #钝角三角形且geo3靠近geo1包括点在线段延长线上的情况
return geo1
elif a + b == c: # 说明点在线段上
return geo3
else:
if geo1[0] == geo2[0]: # 如果直线竖直0---x;1---y)
return [geo1[0], geo3[1]]
elif geo1[1] == geo2[1]: # 如果直线水平
return [geo3[0], geo1[1]]
else:
k = (geo1[1] - geo2[1]) / (geo1[0] - geo2[0]) # y = kx+d中的k
d = geo1[1] - k * geo1[0] # y = kx+d中的d
x4 = (k * geo3[1] - k * d + geo3[0]) / (1 + k**2) #先求交点经度
y4 = k * x4 + d #再求交点纬度
return [x4, y4]
#逐个计算路段的点、与路段延长点、出发点的的夹角
def CalProjectionOfArc(arc, geo):
length = len(arc.geometry_list)
# 先找一个虚拟点其为点arc.geometry_list[-2]到arc.geometry_list[-1]连线延长线上延长相等距离的点virtual_p
virtual_p = [(2 * arc.geometry_list[-1][i] - arc.geometry_list[-2][i]) for i in range(2)]
# 找从哪个i开始三角形ACB变成钝角其中点A为car_record.geo出发点,点C为arc.geometry_list[i]路段的点点B为virtual_p路段延长点
i = 0
while i < length - 1 and CheckOxygon(geo, arc.geometry_list[i], virtual_p): # 判断是否是锐角
i += 1
# 如果最小的i为0或者len() - 1则取最靠近目标点的两个点计算垂点
# 即使第一个点就出现钝角三角形的情况calProjection函数中会处理
if i == 0: # 如果垂点不在线段上
projection = CalProjection(arc.geometry_list[i], arc.geometry_list[i + 1], geo)
else: # 如果垂点在线段上
projection = CalProjection(arc.geometry_list[i - 1], arc.geometry_list[i], geo)
return projection
# 传入geo1, geo2为直线y = kx + d上两点求geo3到直线的距离
# 如果形成钝角三角形则垂点取geo1geo2中靠近geo3的那个点与geo3的距离
def CalDistance(geo1, geo2, geo3):
geo1 = [float(ele) for ele in geo1]
geo2 = [float(ele) for ele in geo2]
geo3 = [float(ele) for ele in geo3]
a = DistanceBetween(geo2, geo3)
b = DistanceBetween(geo1, geo3)
c = DistanceBetween(geo1, geo2)
if (a ** 2 + c ** 2) <= b ** 2: # 钝角三角形且geo3靠近geo2包括点在线段延长线上的情况
return DistanceBetween(geo2, geo3) * 5 # *5是geo点跑到外面去的panelty
elif b ** 2 + c ** 2 <= a ** 2: # 钝角三角形且geo3靠近geo1包括点在线段延长线上的情况
return DistanceBetween(geo1, geo3) * 5
elif a + b == c: # 说明点在线段上
return 0
else:
if geo1[0] == geo2[0]: # 如果直线竖直
return abs(geo3[0] - geo1[0])
elif geo1[1] == geo2[1]: # 如果直线水平
return abs(geo3[1] - geo1[1])
else:
k = (geo1[1] - geo2[1]) / (geo1[0] - geo2[0]) # y = kx+d中的k
d = geo1[1] - k * geo1[0] # y = kx+d中的d
dist = abs(k * geo3[0] + d - geo3[1]) / sqrt(1 + k ** 2) # 点到直线距离公式
return dist
# 如果起点定位跟路线的相差很远或者方向不对则没有必要取该条arc
def CheckNecessary(arc, car_record):
# 计算该地图中最长的路取一半的大一点即1000防止出现漏判的情况因为下面这个if是只取每段道路的坐标的起点和终点来跟目标点计算距离
if DistanceActual(arc.geometry_list[0], car_record.geo) > 1000:
if DistanceActual(arc.geometry_list[-1], car_record.geo) > 1000:
return False
# 下面if是计算这条线路上有一gps点跟目标点的最短距离小于100m才返回True。
min_dist = float("inf")
for geo1 in arc.geometry_list:
tmp = DistanceActual(geo1, car_record.geo)
if tmp < min_dist:
min_dist = tmp
if min_dist < 10:#起点与路线距离的判断
return True
else:
return False
# 计算GPS匹配到该路段的成本系数cost
def CalCost(arc, car_record):
cost = float("inf")#正无穷
# CheckNecessary函数首先排除与起点定位点距离相差远的路段。
if CheckNecessary(arc, car_record):
# arc.geometry_list为路段点集合length记录点个数。
length = len(arc.geometry_list)
# 先找一个虚拟点其为点arc.geometry_list[-2]到arc.geometry_list[-1]连线延长线上延长相等距离的点
# 虚拟点virtual_p在道路最后一个点之后。
virtual_p = [(2 * arc.geometry_list[-1][i] - arc.geometry_list[-2][i]) for i in range(2)]
# 找从哪个i开始三角形ACB变成钝角其中点A为car_record.geo,点C为arc.geometry_list[i]点B为virtual_p
i = 0
# CheckOxygon检查起点与线路第i点的连线与线路的夹角是否为锐角是锐角继续循环。/LOU
while i < length - 1 and CheckOxygon(car_record.geo, arc.geometry_list[i], virtual_p):
i += 1
# 如果最小的i为0或者len() - 1则取最靠近目标点的两个点计算垂点
# 即使出现钝角三角形的情况calProjection函数中会处理
if i == 0:
# dist为起点定位点与道路的距离direction_road为线路方向作为之后计算cost的直接、间接的参数。/LOU
dist = CalDistance(arc.geometry_list[i], arc.geometry_list[i + 1], car_record.geo)
direction_road = arc.direction
else: # 如果垂点在线段上
dist = CalDistance(arc.geometry_list[i - 1], arc.geometry_list[i], car_record.geo)
direction_road = CalDirection(arc.geometry_list[i - 1: i + 1])
# 综合考虑起点与道路距离得出起点定位点与路段匹配的cost。
cost = dist
return cost
# 给定car_geo和car_direction根据最短距离计算在所有道路的Cost返回Cost最小的道路id
def CalMinCostArcID(car_record):
min_cost = float("inf")
id = 0
# arc_objects存储着所有边的Arc对象实例即所有路段信息。
for arc in arc_objects:
cost = CalCost(arc, car_record)
if cost < min_cost:
min_cost = cost
id = arc.id
return id
# 计算时长
def SecondsBetween(t1, t2):
big = datetime.datetime.strptime(str(t2), "%Y-%m-%d %H:%M:%S")#例print(now.strftime('%a, %b %d %H:%M'))输出Mon, May 08 20:22
small = datetime.datetime.strptime(str(t1), "%Y-%m-%d %H:%M:%S")
return (big - small).total_seconds()#用秒统计
# 返回两个点的实际距离x,y与米的换算约为1:111000。不同的比例尺数值不同
def DistanceActual(geo1, geo2):
return pow(pow(float(geo1[0]) - float(geo2[0]), 2) + pow(float(geo1[1]) - float(geo2[1]), 2), 0.5)*111000
# 输入arc_cover是arc_id和cover的列表该函数输出这个arc_cover包含的道路总长
def CalLenCover(arc_cover):
travel_distance = 0
for k in range(len(arc_cover)):
# arc_objects存储着所有边的Arc对象实例即所有路段信息。
travel_distance += arc_objects[arc_cover[k][0] - 1].len * arc_cover[k][1]
return round(travel_distance,1)
# 输入arc_list是arc_id的列表该函数输出这个arc_list包含的道路总长
def CalLen(arc_list):
travel_distance = 0
for k in range(len(arc_list)):
travel_distance += arc_objects[arc_list[k] - 1].len
return round(travel_distance,1)
# 拿着集合找最短的
def findMinDist(dist, collected):
min_dist = float("inf")
min_key = -1
for key in dist:
if dist[key] < min_dist and (key not in collected.keys()):
min_dist = dist[key]
min_key = key
return min_key
# 用单源最短路径算法求两条边的最短距离的arc_list
# graph邻近路网关系图start_arc_id起点路段end_arc_id终点路段
def dijkstra(graph, start_arc_id, end_arc_id):
if start_arc_id == end_arc_id: # 当前一路段与后匹配路段一样
return [start_arc_id]
dist = {}
path = {}
collected = {}
# 初始化距离为无穷大
for key in graph:
dist[key] = float("inf")
for arc in graph[key]:
if not arc.to_node in dist.keys(): # 如果邻近路网关系图中没有路段的起点等于arc的终点则距离设为无穷
dist[arc.to_node] = float("inf")
from_node = arc_objects[start_arc_id - 1].to_node # 起始路段起点
to_node = arc_objects[end_arc_id - 1].from_node # 终止路段终点
if from_node in graph.keys(): # 如果graph中有路段起点与from_node一致
for arc in graph[from_node]: # 遍历路段起点与from_node一致的路段
dist[arc.to_node] = arc.len # 更新始路段起点到该点的距离
path[arc.to_node] = from_node # 更新始路段起点到该点的路径
dist[from_node] = 0 # 起始路段起点到起始路段起点距离为0
collected[from_node] = True
while True:
node = findMinDist(dist, collected)
if node == -1:
break
collected[node] = True
if node in graph.keys():
for arc in graph[node]:
if arc.to_node not in collected.keys():
if dist[arc.to_node] > dist[node] + arc.len:
dist[arc.to_node] = dist[node] + arc.len
path[arc.to_node] = node
arc_list = [end_arc_id]# 先放入终点
while to_node in path.keys():
for arc in graph[path[to_node]]:
if arc.to_node == to_node:
arc_list.append(arc.id)
to_node = path[to_node]
arc_list.append(start_arc_id) #最后放入起点
arc_list = arc_list[::-1] #两级反转
return arc_list
#arc上一个点所匹配的路径car_record点对象distarc终点到点的距离
def BFSFindPathArc(arc, car_record, dist):
min_cost = 60 # min_cost初始值为60近似为无限大
arc_list = [] # arc_list是点从上一个点走过的路径集合
min_arc_id = 0 # min_arc_id是得到最小cost的路段
visited = {} # visited 里面记录着已经搜索过计算过cost的路段
graph_around = {} # graph_around是连接着上一匹配路段的临近路段集合。
q = queue.Queue() # q是一个队列里面存放需要计算cost的备选路段
q.put(arc) # 将arc放入队列
visited[arc.id] = True # 表示arc已经搜索过
while not q.empty(): # 当q里还有需要计算cost的路段则继续循环
arc1 = q.get() # 将q里最后放进去的路段拿出并从q里删除
# 生成arc附近连通的道路的图后面用来找最短路径
if arc1.from_node in graph_around.keys():
graph_around[arc1.from_node].append(arc1) # 将起点ID相同的路段放入同一个索引
else:
graph_around[arc1.from_node] = [arc1]
cost = CalCost(arc1, car_record) # 计算arc1的cost
if cost < min_cost:
min_cost = cost # 更新最小cost
min_arc_id = arc1.id # 更新最小cost的路段
if arc1.to_node in map_graph.keys(): # 如果arc1路段的终点在地图临近关系表map_graph里
for arc2 in map_graph[arc1.to_node]: # 在以arc1路段终点为起点的路段集合里做循环以arc2变量表示
if arc2.id not in visited.keys(): # 如果arc2不在visited集合中
if DistanceBetween(arc.geometry_list[-1], arc2.geometry_list[0]) < dist*1.5:
# 如果arc1终点到arc2的起点的距离 小于 arc终点到GPS点的距离
q.put(arc2) # 将arc2放进队列
visited[arc2.id] = True # 将arc2标记已搜索
if min_arc_id != 0:
arc_list = dijkstra(graph_around, arc.id, min_arc_id) # 计算前一匹配路段到现匹配路段的最短路径
return arc_list
# 计算car_i经过的路径将路段index记录在car_i_start_end_inde_list中路径以j表示
def CarRecordsDivide(car_i):
# car_id_count存储着从1到100每一条OD的定位数量 /LOU
index_start = sum(car_id_count[:car_i-1]) # 第i条OD数据的起始索引位置
index_end = sum(car_id_count[:car_i]) # 第i条OD数据的终止索引位置
car_i_start_end_index_list = []
car_i_start_end_index_list.append([index_start, index_end])
return car_i_start_end_index_list
#计算属于一天中的第几个小时
def Time_stage(gps_time):
today_time=datetime.datetime(2022, 7, 9, 0, 0, 0)
return math.ceil(SecondsBetween(today_time, gps_time)/3600)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 13 KiB

@ -1,7 +0,0 @@
include LICENSE.txt
include README.md
include docs/en/whl_en.md
recursive-include deploy/python predict_cls.py preprocess.py postprocess.py det_preprocess.py
recursive-include deploy/utils get_image_list.py config.py logger.py predictor.py
recursive-include ppcls/ *.py *.txt

@ -1,17 +0,0 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__all__ = ['PaddleClas']
from .paddleclas import PaddleClas
from ppcls.arch.backbone import *

@ -1,27 +0,0 @@
# benchmark使用说明
此目录所有shell脚本是为了测试PaddleClas中不同模型的速度指标如单卡训练速度指标、多卡训练速度指标等。
## 相关脚本说明
一共有3个脚本
- `prepare_data.sh`: 下载相应的测试数据,并配置好数据路径
- `run_benchmark.sh`: 执行单独一个训练测试的脚本,具体调用方式,可查看脚本注释
- `run_all.sh`: 执行所有训练测试的入口脚本
## 使用说明
**注意**为了跟PaddleClas中其他的模块的执行目录保持一致此模块的执行目录为`PaddleClas`的根目录。
### 1.准备数据
```shell
bash benchmark/prepare_data.sh
```
### 2.执行所有模型的测试
```shell
bash benchmark/run_all.sh
```

@ -1,22 +0,0 @@
#!/bin/bash
dataset_url=$1
package_check_list=(imageio tqdm Cython pycocotools tb_paddle scipy pandas wget h5py sklearn opencv-python visualdl)
for package in ${package_check_list[@]}; do
if python -c "import ${package}" >/dev/null 2>&1; then
echo "${package} have already installed"
else
echo "${package} NOT FOUND"
pip install ${package}
echo "${package} installed"
fi
done
cd dataset
rm -rf ILSVRC2012
wget -nc ${dataset_url}
tar xf ILSVRC2012_val.tar
ln -s ILSVRC2012_val ILSVRC2012
cd ILSVRC2012
ln -s val_list.txt train_list.txt
cd ../../

@ -1,31 +0,0 @@
# 提供可稳定复现性能的脚本默认在标准docker环境内py37执行 paddlepaddle/paddle:latest-gpu-cuda10.1-cudnn7 paddle=2.1.2 py=37
# 执行目录:需说明
# cd **
# 1 安装该模型需要的依赖 (如需开启优化策略请注明)
# pip install ...
# 2 拷贝该模型需要数据、预训练模型
# 3 批量运行如不方便批量12需放到单个模型中
log_path=${LOG_PATH_INDEX_DIR:-$(pwd)} # LOG_PATH_INDEX_DIR 后续QA设置参数
model_mode_list=(MobileNetV1 MobileNetV2 MobileNetV3_large_x1_0 ShuffleNetV2_x1_0 HRNet_W48_C SwinTransformer_tiny_patch4_window7_224 alt_gvt_base) # benchmark 监控模型列表
#model_mode_list=(MobileNetV1 MobileNetV2 MobileNetV3_large_x1_0 EfficientNetB0 ShuffleNetV2_x1_0 DenseNet121 HRNet_W48_C SwinTransformer_tiny_patch4_window7_224 alt_gvt_base) # 该脚本支持列表
fp_item_list=(fp32)
#bs_list=(32 64 96 128)
for model_mode in ${model_mode_list[@]}; do
for fp_item in ${fp_item_list[@]}; do
if [ ${model_mode} = MobileNetV3_large_x1_0 ] || [ ${model_mode} = ShuffleNetV2_x1_0 ]; then
bs_list=(256)
else
bs_list=(64)
fi
for bs_item in ${bs_list[@]};do
echo "index is speed, 1gpus, begin, ${model_name}"
run_mode=sp
CUDA_VISIBLE_DEVICES=0 bash benchmark/run_benchmark.sh ${run_mode} ${bs_item} ${fp_item} 1 ${model_mode} | tee ${log_path}/clas_${model_mode}_${run_mode}_bs${bs_item}_${fp_item}_1gpus 2>&1 # (5min)
sleep 10
echo "index is speed, 8gpus, run_mode is multi_process, begin, ${model_name}"
run_mode=mp
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash benchmark/run_benchmark.sh ${run_mode} ${bs_item} ${fp_item} 1 ${model_mode}| tee ${log_path}/clas_${model_mode}_${run_mode}_bs${bs_item}_${fp_item}_8gpus8p 2>&1
sleep 10
done
done
done

@ -1,68 +0,0 @@
#!/usr/bin/env bash
set -xe
# 运行示例CUDA_VISIBLE_DEVICES=0 bash run_benchmark.sh ${run_mode} ${bs_item} ${fp_item} 500 ${model_mode}
# 参数说明
function _set_params(){
run_mode=${1:-"sp"} # 单卡sp|多卡mp
batch_size=${2:-"64"}
fp_item=${3:-"fp32"} # fp32|fp16
epochs=${4:-"2"} # 可选,如果需要修改代码提前中断
model_item=${5:-"model_item"}
run_log_path=${TRAIN_LOG_DIR:-$(pwd)} # TRAIN_LOG_DIR 后续QA设置该参数
index=1
mission_name="图像分类" # 模型所属任务名称具体可参考scripts/config.ini (必填)
direction_id=0 # 任务所属方向0CV1NLP2Rec。 (必填)
skip_steps=8 # 解析日志有些模型前几个step耗时长需要跳过 (必填)
keyword="ips:" # 解析日志,筛选出数据所在行的关键字 (必填)
keyword_loss="loss:" #选填
model_mode=-1 # 解析日志具体参考scripts/analysis.py. (必填)
ips_unit="images/s"
base_batch_size=$batch_size
# 以下不用修改
device=${CUDA_VISIBLE_DEVICES//,/ }
arr=(${device})
num_gpu_devices=${#arr[*]}
log_file=${run_log_path}/clas_${model_item}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}
model_name=${model_item}_bs${batch_size}_${fp_item} # model_item 用于yml匹配model_name用于入库
}
function _train(){
echo "Train on ${num_gpu_devices} GPUs"
echo "current CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES, gpus=$num_gpu_devices, batch_size=$batch_size"
if [ ${fp_item} = "fp32" ];then
model_config=`find ppcls/configs/ImageNet -name ${model_item}.yaml`
else
model_config=`find ppcls/configs/ImageNet -name ${model_item}_fp16.yaml`
fi
train_cmd="-c ${model_config} -o DataLoader.Train.sampler.batch_size=${batch_size} -o Global.epochs=${epochs} -o Global.eval_during_train=False -o Global.print_batch_step=2"
case ${run_mode} in
sp) train_cmd="python -u tools/train.py ${train_cmd}" ;;
mp)
train_cmd="python -m paddle.distributed.launch --log_dir=./mylog --gpus=$CUDA_VISIBLE_DEVICES tools/train.py ${train_cmd}"
log_parse_file="mylog/workerlog.0" ;;
*) echo "choose run_mode(sp or mp)"; exit 1;
esac
rm -rf mylog
# 以下不用修改
timeout 5m ${train_cmd} > ${log_file} 2>&1
if [ $? -ne 0 ];then
echo -e "${model_name}, FAIL"
export job_fail_flag=1
else
echo -e "${model_name}, SUCCESS"
export job_fail_flag=0
fi
kill -9 `ps -ef|grep 'python'|awk '{print $2}'`
if [ $run_mode = "mp" -a -d mylog ]; then
rm ${log_file}
cp mylog/workerlog.0 ${log_file}
fi
}
source ${BENCHMARK_ROOT}/scripts/run_model.sh # 在该脚本中会对符合benchmark规范的log使用analysis.py 脚本进行性能数据解析;该脚本在连调时可从benchmark repo中下载https://github.com/PaddlePaddle/benchmark/blob/master/scripts/run_model.sh;如果不联调只想要产出训练log可以注掉本行,提交时需打开
_set_params $@
_run
#_train

@ -1,3 +0,0 @@
# 默认忽略的文件
/shelf/
/workspace.xml

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="GOOGLE" />
<option name="myDocStringFormat" value="Google" />
</component>
</module>

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/deploy.iml" filepath="$PROJECT_DIR$/.idea/deploy.iml" />
</modules>
</component>
</project>

@ -1,6 +0,0 @@
projectKey=deploy
serverUrl=http://localhost:9000
serverVersion=8.1.0.31237
dashboardUrl=http://localhost:9000/dashboard?id=deploy
ceTaskId=AYA_xvBwrgFtfprwzYuQ
ceTaskUrl=http://localhost:9000/api/ce/task?id=AYA_xvBwrgFtfprwzYuQ

Binary file not shown.

Before

Width:  |  Height:  |  Size: 559 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 542 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 472 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 477 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 432 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 548 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save