-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed few small bugs
- Loading branch information
fcdl94
authored and
fcdl94
committed
Jul 21, 2020
1 parent
416fca8
commit 3f5c6dd
Showing
13 changed files
with
299 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
#PyCharm | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import torch | ||
from .method import FineTuning | ||
import torch.nn as nn | ||
from .utils import get_scheduler | ||
import torch.nn.functional as F | ||
from .segmentation_module import make_model | ||
|
||
|
||
class Classifier(nn.Module): | ||
def __init__(self, channels, classes): | ||
super().__init__() | ||
self.cls = nn.ModuleList( | ||
[nn.Conv2d(channels, c, 1, bias=False) for c in classes]) | ||
self.scaler = 10. | ||
|
||
def forward(self, x): | ||
x = F.normalize(x, p=2, dim=1) | ||
out = [] | ||
for i, mod in enumerate(self.cls): | ||
out.append(self.scaler * F.conv2d(x, F.normalize(mod.weight, dim=1, p=2))) | ||
return torch.cat(out, dim=1) | ||
|
||
|
||
class CosineFT(FineTuning): | ||
def initialize(self, opts): | ||
|
||
head_channels = 256 | ||
self.model = make_model(opts, head_channels, Classifier(head_channels, self.task.get_n_classes())) | ||
|
||
if opts.fix_bn: | ||
self.model.fix_bn() | ||
|
||
# xxx Set up optimizer | ||
params = [] | ||
params.append({"params": filter(lambda p: p.requires_grad, self.model.body.parameters()), | ||
'weight_decay': opts.weight_decay}) | ||
|
||
params.append({"params": filter(lambda p: p.requires_grad, self.model.head.parameters()), | ||
'weight_decay': opts.weight_decay, 'lr': opts.lr*10.}) | ||
|
||
params.append({"params": filter(lambda p: p.requires_grad, self.model.cls.parameters()), | ||
'weight_decay': opts.weight_decay, 'lr': opts.lr*10.}) | ||
|
||
self.optimizer = torch.optim.SGD(params, lr=opts.lr, momentum=0.9, nesterov=False) | ||
|
||
self.scheduler = get_scheduler(opts, self.optimizer) | ||
self.logger.debug("Optimizer:\n%s" % self.optimizer) | ||
|
||
reduction = 'mean' | ||
self.criterion = nn.CrossEntropyLoss(ignore_index=255, reduction=reduction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.