target = ET.parse(annopath % image_id).getroot()
res = []
for obj in target.iter('object'):
difficult = int(obj.find('difficult').text) == 1
if not keep_difficult and difficult:
continue
name = obj.find('name').text.lower().strip()
bbox = obj.find('bndbox')
pts = ['xmin', 'ymin', 'xmax', 'ymax']
bndbox = []
for i, pt in enumerate(pts):
cur_pt = int(bbox.find(pt).text) - 1
# scale height or width
cur_pt = float(cur_pt) / width if i % 2 == 0 else float(cur_pt) / height
bndbox.append(cur_pt)
label_idx = dict(zip(CLASSES, range(len(CLASSES))))[name]
bndbox.append(label_idx)
res += [bndbox] # [xmin, ymin, xmax, ymax, label\_ind]
# img\_id = target.find('filename').text[:-4]
try :
np.array(res)[:,4]
np.array(res)[:,:4]
except IndexError:
print(image_id+" had error index")
return res # [[xmin, ymin, xmax, ymax, label\_ind], ... ]
if name == ‘__main__’ :
i = 0
for name in sorted(os.listdir(osp.join(args.root,‘Annotations’))):
# as we have only one annotations file per image
i += 1
img = cv2.imread(imgpath % (args.root,name.split(‘.’)[0]))
height, width, channels = img.shape
res = vocChecker((args.root, name.split(‘.’)[0]), height, width)
print(“Total of annotations : {}”.format(i))
### 二、代码修改
1. 修改`data/voc0712.py`文件中的`VOC_CLASSES` 变量。例如,将VOC\_CLASSES修改为person类,**注意如果只有一类则需要加方括号**,修改后的结果如下。
VOC_CLASSES = [(‘person’)
2. 修改`voc0712.py`文件中`VOCDetection`类的`__init__`函数,将`image_sets`修改为`[('2020', 'train'), ('2020', 'val'),('2020','test')]`,修改后的结果如下。
def __init__(self, root,
image_sets=[(‘2020’, ‘train’), (‘2020’, ‘val’),(‘2020’,‘test’)],
transform=None, target_transform=VOCAnnotationTransform(),
dataset_name=‘VOC0712’):
3. 修改`config.py`文件中的`voc`字典变量。将其中的`num_classes`修改为2(背景类和person类),第一次调试时可以将`max_iter`调小至1000,修改后的结果如下。
voc = {
‘num_classes’: 2,
‘lr_steps’: (80000, 100000, 120000),
‘max_iter’: 1000,
‘feature_maps’: [38, 19, 10, 5, 3, 1],
‘min_dim’: 300,
‘steps’: [8, 16, 32, 64, 100, 300],
‘min_sizes’: [30, 60, 111, 162, 213, 264],
‘max_sizes’: [60, 111, 162, 213, 264, 315],
‘aspect_ratios’: [[2], [2, 3], [2, 3], [2, 3], [2], [2]],
‘variance’: [0.1, 0.2],
‘clip’: True,
‘name’: ‘VOC’,
}
4. 把`coco_labels.txt`放在`ssd.pytorch-master/data/coco/`目录下,也可以通过修改`coco.py`文件中的`COCO_ROOT = osp.join(HOME, 'data/coco/')`来指定存放路径。
5. 在Pytorch1.3以上版本运行时,会出现`RuntimeError: Legacy autograd function with non-static forward method is deprecated`错误,原因是当前版本要求forward过程是静态的,所以需要将原代码进行修改。
将`layers/functions/detection.py`文件替换为`Single-Shot-Object-Detection-Updated-master`中的`detection.py`文件。
修改`ssd.py`文件中`SSD`类的`__init__`函数和`forward`函数,修改后的结果如下。
if phase == ‘test’:
self.softmax = nn.Softmax(dim=-1)
self.detect = Detect(num_classes, 0, 200, 0.01, 0.45)
修改为:
if phase == ‘test’:
self.softmax = nn.Softmax()
self.detect = Detect()
if self.phase == “test”:
output = self.detect(
loc.view(loc.size(0), -1, 4), # loc preds
self.softmax(conf.view(conf.size(0), -1,
self.num_classes)), # conf preds
self.priors.type(type(x.data)) # default boxes
)
修改为:
if self.phase == “test”:
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Linux运维工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。





既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Linux运维知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加VX:vip1024b (备注Linux运维获取)

源码讲义、实战项目、讲解视频,并且后续会持续更新**
如果你觉得这些内容对你有帮助,可以添加VX:vip1024b (备注Linux运维获取)
[外链图片转存中…(img-0T5pjHBw-1712550640154)]
7488

被折叠的 条评论
为什么被折叠?



