Skip to content

Commit

Permalink
add missing lib folder
Browse files Browse the repository at this point in the history
  • Loading branch information
umgupta committed May 26, 2021
1 parent 703729e commit 27181f8
Show file tree
Hide file tree
Showing 16 changed files with 1,287 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dist/
downloads/
eggs/
.eggs/
lib/

lib64/
parts/
sdist/
Expand Down Expand Up @@ -108,4 +108,4 @@ results
.idea


result/
result/
108 changes: 108 additions & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# 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/

.vscode
results
.idea
2 changes: 2 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# train-lib
Common code for different projects
31 changes: 31 additions & 0 deletions lib/base_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
""" base model"""
import logging

import numpy as np
import torch.nn as nn

logger = logging.getLogger()


class Base(nn.Module):
""" Base model with some util functions"""

def stats(self, print_model=True):
# print network model and information about parameters
logger.info("Model info:::")
if print_model:
logger.info(self)
count = 0
for i in self.parameters():
count += np.prod(i.shape)
logger.info(f"Total parameters : {count}")

def to(self, *args, **kwargs):
if kwargs.get("device"):
self.device = kwargs.get("device")
if len(args) > 0:
self.device = args[0]
return super().to(*args, **kwargs)

def forward(self, x):
raise NotImplementedError()
Loading

0 comments on commit 27181f8

Please # to comment.