Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sliding_fixed #1726

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9af66ea
Add files via upload
lujulia Jul 9, 2022
6b262d2
Add files via upload
lujulia Jul 9, 2022
812f20e
Rename nano.py to yolox_nano.py
lujulia Jul 9, 2022
9950ca2
Rename nano.py to yolox_nano.py
lujulia Jul 9, 2022
d09ad1d
Delete exps/example/yolox_voc directory
lujulia Jul 9, 2022
66a3ead
Delete exps/example/yolox_voc_nano directory
lujulia Jul 9, 2022
910165d
Delete exps/example/yolox_voc_nano_adam directory
lujulia Jul 9, 2022
0827b55
Delete exps/example/yolox_voc_tiny directory
lujulia Jul 9, 2022
4175e9e
Add files via upload
lujulia Jul 9, 2022
a0499df
Add files via upload
lujulia Jul 9, 2022
fae9df3
Delete yolox_nano.py
lujulia Jul 9, 2022
1af2ef8
Delete yolox_s.py
lujulia Jul 9, 2022
6ed55a4
Rename nano.py to yolox_nano.py
lujulia Jul 9, 2022
d162dc8
Update demo.py
lujulia Jul 9, 2022
0ae6ad6
Update __init__.py
lujulia Jul 9, 2022
2d74703
Update coco_classes.py
lujulia Jul 9, 2022
2f882f3
Update coco.py
lujulia Jul 9, 2022
8087d10
Update voc_classes.py
lujulia Jul 9, 2022
716a82f
Update voc.py
lujulia Jul 9, 2022
b274e8b
Update yolox_base.py
lujulia Jul 10, 2022
2891d23
Update visualize.py
lujulia Jul 10, 2022
1d8f8df
Add files via upload
lujulia Jul 10, 2022
bf8e247
Delete datasets directory
lujulia Jul 10, 2022
83a313d
Add files via upload
lujulia Jul 10, 2022
2231daa
Add files via upload
lujulia Jul 10, 2022
44be20e
Update yolox_voc_s.py
lujulia Jul 10, 2022
8fd95f6
Update yolox_nano.py
lujulia Jul 10, 2022
1ea66fd
Update yolox_s.py
lujulia Jul 10, 2022
6823fda
Update yolox_voc_nano.py
lujulia Jul 10, 2022
feed57d
Update yolox_voc_nano.py
lujulia Jul 10, 2022
ce9d0e1
Update yolox_voc_tiny.py
lujulia Jul 10, 2022
0eaf0b8
Update yolox_voc_tiny.py
lujulia Jul 10, 2022
96de204
Update yolox_voc_nano_adam.py
lujulia Jul 10, 2022
9a858cd
Update demo.py
lujulia Jul 10, 2022
4a1acd4
Update coco.py
lujulia Jul 10, 2022
843ce1b
Update voc.py
lujulia Jul 10, 2022
7643143
Update voc.py
lujulia Jul 10, 2022
82e7098
Update visualize.py
lujulia Jul 10, 2022
ea7a361
Update yolox_base.py
lujulia Jul 10, 2022
fdc26eb
Update yolox_base.py
lujulia Jul 10, 2022
18a6d9e
Update yolox_voc_nano.py
lujulia Jul 10, 2022
2adbb06
Update yolox_voc_nano.py
lujulia Jul 10, 2022
f3a902b
Update yolox_voc_nano.py
lujulia Jul 10, 2022
58dd583
Update yolox_voc_s.py
lujulia Jul 10, 2022
8dd855b
Update yolox_voc_nano_adam.py
lujulia Jul 10, 2022
79c3315
Update yolox_voc_nano_adam.py
lujulia Jul 10, 2022
33954ea
Update demo.py
lujulia Jul 10, 2022
f983881
Update requirements.txt
lujulia Jul 10, 2022
577c62f
Update demo.py
lujulia Jul 10, 2022
16eb42a
Update data_augment.py
lujulia Jul 11, 2022
8c9bba3
Update visualize.py
lujulia Jul 11, 2022
a73cef1
Update demo.py
lujulia Jul 11, 2022
fefd852
Add files via upload
lujulia Jul 11, 2022
a3532ca
Update visualize.py
lujulia Jul 12, 2022
e261097
Update visualize.py
lujulia Jul 15, 2022
cf8685e
Update README.md
lujulia Sep 9, 2023
ff2a91c
Update README.md
lujulia Sep 9, 2023
8fb0fbe
Update demo_sliding_window.py
lujulia Sep 27, 2023
0969432
Update demo_sliding_window.py
lujulia Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

<div align="center"><img src="assets/logo.png" width="350"></div>
<img src="assets/demo.png" >

<div align="center"><img src="assets/logo.png" width="350"></div>
<img src="assets/demo.png" >

Expand Down Expand Up @@ -246,4 +250,4 @@ It is hoped that every AI practitioner in the world will stick to the concept of
<div align="center"><img src="assets/sunjian.png" width="200"></div>
没有孙剑博士的指导,YOLOX也不会问世并开源给社区使用。
孙剑博士的离去是CV领域的一大损失,我们在此特别添加了这个部分来表达对我们的“船长”孙老师的纪念和哀思。
希望世界上的每个AI从业者秉持着“持续创新拓展认知边界,非凡科技成就产品价值”的观念,一路向前。
希望世界上的每个AI从业者秉持着“持续创新拓展认知边界,非凡科技成就产品价值”的观念,一路向前。
Empty file.
Empty file.
1 change: 1 addition & 0 deletions datasets/pedestrian_coco/train/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put the train images
1 change: 1 addition & 0 deletions datasets/pedestrian_coco/valid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put the valid images
1 change: 1 addition & 0 deletions datasets/pedestrian_voc/Annotations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put the train and valid annotations
Empty file.
Empty file.
1 change: 1 addition & 0 deletions datasets/pedestrian_voc/JPEGImages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put the train and valid images
Binary file not shown.
163 changes: 163 additions & 0 deletions exps/example/custom/voc_format/yolox_voc_nano/yolox_voc_nano.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

import torch
import torch.distributed as dist

from yolox.data import get_yolox_datadir
from yolox.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.num_classes = 20
self.depth = 0.33
self.width = 0.25
self.input_size = (416, 416)
self.mosaic_scale = (0.5, 1.5)
self.random_size = (10, 20)
self.test_size = (416, 416)
self.warmup_epochs = 1
# ---------- transform config ------------ #
#self.mosaic_prob = 1.0
self.enable_mixup = False
#self.mixup_prob = 1.0
#self.hsv_prob = 1.0
#self.flip_prob = 0.5
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]

def get_model(self, sublinear=False):

def init_yolo(M):
for m in M.modules():
if isinstance(m, nn.BatchNorm2d):
m.eps = 1e-3
m.momentum = 0.03
if "model" not in self.__dict__:
from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
in_channels = [256, 512, 1024]
# NANO model use depthwise = True, which is main difference.
backbone = YOLOPAFPN(self.depth, self.width, in_channels=in_channels, depthwise=True)
head = YOLOXHead(self.num_classes, self.width, in_channels=in_channels, depthwise=True)
self.model = YOLOX(backbone, head)

self.model.apply(init_yolo)
self.model.head.initialize_biases(1e-2)
return self.model

def get_data_loader(self, batch_size, is_distributed, no_aug=False, cache_img=False):
from yolox.data import (
VOCDetection,
TrainTransform,
YoloBatchSampler,
DataLoader,
InfiniteSampler,
MosaicDetection,
worker_init_reset_seed,
)
from yolox.utils import (
wait_for_the_master,
get_local_rank,
)
local_rank = get_local_rank()

with wait_for_the_master(local_rank):
dataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "pedestrian_voc"),
image_sets=[('train')],
img_size=self.input_size,
preproc=TrainTransform(
max_labels=50,
flip_prob=self.flip_prob,
hsv_prob=self.hsv_prob),
cache=cache_img,
)

dataset = MosaicDetection(
dataset,
mosaic=not no_aug,
img_size=self.input_size,
preproc=TrainTransform(
max_labels=120,
flip_prob=self.flip_prob,
hsv_prob=self.hsv_prob),
degrees=self.degrees,
translate=self.translate,
mosaic_scale=self.mosaic_scale,
mixup_scale=self.mixup_scale,
shear=self.shear,
enable_mixup=self.enable_mixup,
mosaic_prob=self.mosaic_prob,
mixup_prob=self.mixup_prob,
)

self.dataset = dataset

if is_distributed:
batch_size = batch_size // dist.get_world_size()

sampler = InfiniteSampler(
len(self.dataset), seed=self.seed if self.seed else 0
)

batch_sampler = YoloBatchSampler(
sampler=sampler,
batch_size=batch_size,
drop_last=False,
mosaic=not no_aug,
)

dataloader_kwargs = {"num_workers": self.data_num_workers, "pin_memory": True}
dataloader_kwargs["batch_sampler"] = batch_sampler

# Make sure each process has different random seed, especially for 'fork' method
dataloader_kwargs["worker_init_fn"] = worker_init_reset_seed

train_loader = DataLoader(self.dataset, **dataloader_kwargs)

return train_loader

def get_eval_loader(self, batch_size, is_distributed, testdev=False, legacy=False):
from yolox.data import VOCDetection, ValTransform

valdataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "pedestrian_voc"),
image_sets=[('valid')],
img_size=self.test_size,
preproc=ValTransform(legacy=legacy),
)

if is_distributed:
batch_size = batch_size // dist.get_world_size()
sampler = torch.utils.data.distributed.DistributedSampler(
valdataset, shuffle=False
)
else:
sampler = torch.utils.data.SequentialSampler(valdataset)

dataloader_kwargs = {
"num_workers": self.data_num_workers,
"pin_memory": True,
"sampler": sampler,
}
dataloader_kwargs["batch_size"] = batch_size
val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs)

return val_loader

def get_evaluator(self, batch_size, is_distributed, testdev=False, legacy=False):
from yolox.evaluators import VOCEvaluator

val_loader = self.get_eval_loader(batch_size, is_distributed, testdev, legacy)
evaluator = VOCEvaluator(
dataloader=val_loader,
img_size=self.test_size,
confthre=self.test_conf,
nmsthre=self.nmsthre,
num_classes=self.num_classes,
)
return evaluator
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

import torch
import torch.distributed as dist

from yolox.data import get_yolox_datadir
from yolox.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.num_classes = 20
self.depth = 0.33
self.width = 0.25
self.input_size = (416, 416)
self.mosaic_scale = (0.5, 1.5)
self.random_size = (10, 20)
self.test_size = (416, 416)
self.eps = 1e-8
self.warmup_epochs = 1
# ---------- transform config ------------ #
#self.mosaic_prob = 1.0
self.enable_mixup = False
#self.mixup_prob = 1.0
#self.hsv_prob = 1.0
#self.flip_prob = 0.5
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]

def get_model(self, sublinear=False):

def init_yolo(M):
for m in M.modules():
if isinstance(m, nn.BatchNorm2d):
m.eps = 1e-3
m.momentum = 0.03
if "model" not in self.__dict__:
from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
in_channels = [256, 512, 1024]
# NANO model use depthwise = True, which is main difference.
backbone = YOLOPAFPN(self.depth, self.width, in_channels=in_channels, depthwise=True)
head = YOLOXHead(self.num_classes, self.width, in_channels=in_channels, depthwise=True)
self.model = YOLOX(backbone, head)

self.model.apply(init_yolo)
self.model.head.initialize_biases(1e-2)
return self.model

def get_optimizer(self, batch_size):
if "optimizer" not in self.__dict__:
if self.warmup_epochs > 0:
lr = self.warmup_lr
else:
lr = self.basic_lr_per_img * batch_size

pg0, pg1, pg2 = [], [], [] # optimizer parameter groups

for k, v in self.model.named_modules():
if hasattr(v, "bias") and isinstance(v.bias, nn.Parameter):
pg2.append(v.bias) # biases
if isinstance(v, nn.BatchNorm2d) or "bn" in k:
pg0.append(v.weight) # no decay
elif hasattr(v, "weight") and isinstance(v.weight, nn.Parameter):
pg1.append(v.weight) # apply decay

optimizer = torch.optim.Adam(
pg0, lr=lr, eps=self.eps, amsgrad=False
)
optimizer.add_param_group(
{"params": pg1, "weight_decay": self.weight_decay}
) # add pg1 with weight_decay
optimizer.add_param_group({"params": pg2})
self.optimizer = optimizer
return self.optimizer

def get_data_loader(self, batch_size, is_distributed, no_aug=False, cache_img=False):
from yolox.data import (
VOCDetection,
TrainTransform,
YoloBatchSampler,
DataLoader,
InfiniteSampler,
MosaicDetection,
worker_init_reset_seed,
)
from yolox.utils import (
wait_for_the_master,
get_local_rank,
)
local_rank = get_local_rank()

with wait_for_the_master(local_rank):
dataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
image_sets=[('2007', 'trainval'), ('2012', 'trainval')],
img_size=self.input_size,
preproc=TrainTransform(
max_labels=50,
flip_prob=self.flip_prob,
hsv_prob=self.hsv_prob),
cache=cache_img,
)

dataset = MosaicDetection(
dataset,
mosaic=not no_aug,
img_size=self.input_size,
preproc=TrainTransform(
max_labels=120,
flip_prob=self.flip_prob,
hsv_prob=self.hsv_prob),
degrees=self.degrees,
translate=self.translate,
mosaic_scale=self.mosaic_scale,
mixup_scale=self.mixup_scale,
shear=self.shear,
enable_mixup=self.enable_mixup,
mosaic_prob=self.mosaic_prob,
mixup_prob=self.mixup_prob,
)

self.dataset = dataset

if is_distributed:
batch_size = batch_size // dist.get_world_size()

sampler = InfiniteSampler(
len(self.dataset), seed=self.seed if self.seed else 0
)

batch_sampler = YoloBatchSampler(
sampler=sampler,
batch_size=batch_size,
drop_last=False,
mosaic=not no_aug,
)

dataloader_kwargs = {"num_workers": self.data_num_workers, "pin_memory": True}
dataloader_kwargs["batch_sampler"] = batch_sampler

# Make sure each process has different random seed, especially for 'fork' method
dataloader_kwargs["worker_init_fn"] = worker_init_reset_seed

train_loader = DataLoader(self.dataset, **dataloader_kwargs)

return train_loader

def get_eval_loader(self, batch_size, is_distributed, testdev=False, legacy=False):
from yolox.data import VOCDetection, ValTransform

valdataset = VOCDetection(
data_dir=os.path.join(get_yolox_datadir(), "VOCdevkit"),
image_sets=[('2007', 'test')],
img_size=self.test_size,
preproc=ValTransform(legacy=legacy),
)

if is_distributed:
batch_size = batch_size // dist.get_world_size()
sampler = torch.utils.data.distributed.DistributedSampler(
valdataset, shuffle=False
)
else:
sampler = torch.utils.data.SequentialSampler(valdataset)

dataloader_kwargs = {
"num_workers": self.data_num_workers,
"pin_memory": True,
"sampler": sampler,
}
dataloader_kwargs["batch_size"] = batch_size
val_loader = torch.utils.data.DataLoader(valdataset, **dataloader_kwargs)

return val_loader

def get_evaluator(self, batch_size, is_distributed, testdev=False, legacy=False):
from yolox.evaluators import VOCEvaluator

val_loader = self.get_eval_loader(batch_size, is_distributed, testdev, legacy)
evaluator = VOCEvaluator(
dataloader=val_loader,
img_size=self.test_size,
confthre=self.test_conf,
nmsthre=self.nmsthre,
num_classes=self.num_classes,
)
return evaluator
Binary file not shown.
Loading