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

refactor: Cleaned codebase #44

Merged
merged 6 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ conda install -c frgfm pylocron

- Classification: [Res2Net](https://arxiv.org/abs/1904.01169) (based on the great [implementation](https://github.com/gasvn/Res2Net) from gasvn), [darknet24](https://pjreddie.com/media/files/papers/yolo_1.pdf), [darknet19](https://pjreddie.com/media/files/papers/YOLO9000.pdf), [darknet53](https://pjreddie.com/media/files/papers/YOLOv3.pdf).
- Detection: [YOLOv1](https://pjreddie.com/media/files/papers/yolo_1.pdf), [YOLOv2](https://pjreddie.com/media/files/papers/YOLO9000.pdf)
- Segmentation: [U-Net](https://arxiv.org/abs/1505.04597)

### ops

Expand Down
17 changes: 2 additions & 15 deletions holocron/models/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@


class DarkBlockV1(nn.Sequential):

def __init__(self, planes):

layers = []
Expand Down Expand Up @@ -74,7 +73,6 @@ def forward(self, x):


class DarknetV1(nn.Sequential):

def __init__(self, layout, num_classes=10):

super().__init__(OrderedDict([
Expand All @@ -86,7 +84,6 @@ def __init__(self, layout, num_classes=10):


class DarkBlockV2(nn.Sequential):

def __init__(self, in_planes, out_planes, nb_compressions=0):

layers = [conv3x3(in_planes, out_planes),
Expand All @@ -104,7 +101,6 @@ def __init__(self, in_planes, out_planes, nb_compressions=0):


class DarknetBodyV2(nn.Module):

def __init__(self, layout, passthrough=False):

super().__init__()
Expand Down Expand Up @@ -141,7 +137,6 @@ def forward(self, x):


class DarknetV2(nn.Sequential):

def __init__(self, layout, num_classes=10):

super().__init__(OrderedDict([
Expand All @@ -153,14 +148,6 @@ def __init__(self, layout, num_classes=10):


class DarkBlockV3(nn.Module):
"""Implements a residual block of Darknet as described in
`"YOLOv3: An Incremental Improvement" <https://pjreddie.com/media/files/papers/YOLOv3.pdf>`_

Args:
planes (int): number of input/output channels
mid_planes (int): number of intermediate channels
"""

def __init__(self, planes, mid_planes):

super().__init__()
Expand Down Expand Up @@ -192,7 +179,8 @@ def forward(self, x):

class DarknetBodyV3(nn.Module):

def _make_layer(self, num_blocks, in_planes, out_planes=None):
@staticmethod
def _make_layer(num_blocks, in_planes, out_planes=None):

layers = [DarkBlockV3(in_planes, in_planes // 2) for _ in range(num_blocks)]
if isinstance(out_planes, int):
Expand Down Expand Up @@ -240,7 +228,6 @@ def forward(self, x):


class DarknetV3(nn.Sequential):

def __init__(self, layout, num_classes=10):

super().__init__(OrderedDict([
Expand Down
2 changes: 0 additions & 2 deletions holocron/models/detection/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def post_process(b_coords, b_o, b_scores, rpn_nms_thresh=0.7, box_score_thresh=0


class YOLOv1(_YOLO):

def __init__(self, layout, num_classes=20, num_anchors=2, lambda_noobj=0.5, lambda_coords=5.):

super().__init__()
Expand Down Expand Up @@ -285,7 +284,6 @@ def forward(self, x, gt_boxes=None, gt_labels=None):


class YOLOv2(_YOLO):

def __init__(self, layout, num_classes=20, anchors=None, lambda_noobj=0.5, lambda_coords=5.):

super().__init__()
Expand Down
3 changes: 2 additions & 1 deletion holocron/optim/lr_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def __init__(self,

super(OneCycleScheduler, self).__init__(optimizer, last_epoch)

def _format_param(self, name, optimizer, param):
@staticmethod
def _format_param(name, optimizer, param):
"""Return correctly formatted lr/momentum for each param group."""
if isinstance(param, (list, tuple)):
if len(param) != len(optimizer.param_groups):
Expand Down
1 change: 0 additions & 1 deletion references/classification/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from torch import nn
import torchvision
from torchvision import transforms
from torchvision.transforms import functional as F

import holocron

Expand Down
6 changes: 1 addition & 5 deletions references/detection/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

import math
import datetime
import os
import time
from pathlib import Path
from tqdm import tqdm
from fastprogress import master_bar, progress_bar
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

import torch
import torch.utils.data
from torch import nn
import torchvision
from torchvision import transforms
from torchvision.datasets import VOCDetection
from torchvision.ops.boxes import box_iou
Expand Down Expand Up @@ -179,7 +175,7 @@ def plot_lr_finder(train_batch, model, data_loader, optimizer, device,
def plot_samples(images, targets):
# Unnormalize image
nb_samples = 4
fig, axes = plt.subplots(1, nb_samples, figsize=(20, 5))
_, axes = plt.subplots(1, nb_samples, figsize=(20, 5))
for idx in range(nb_samples):
img = images[idx]
img *= torch.tensor([0.229, 0.224, 0.225]).view(-1, 1, 1)
Expand Down