Skip to content

Commit a903e89

Browse files
authored
Merge pull request #349 from Visual-Behavior/dev
Dev
2 parents e78bdac + 8e820ba commit a903e89

File tree

18 files changed

+676
-74
lines changed

18 files changed

+676
-74
lines changed

Dockerfile

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
1-
# tagged aloception-oss:cuda-11.3.1-pytorch1.10.1-lightning1.4.1
2-
31
FROM nvidia/cuda:11.3.1-cudnn8-devel-ubuntu20.04
4-
#FROM nvidia/cuda:11.6.0-cudnn8-devel-ubuntu20.04
52

3+
#ARG py=3.9
4+
#ARG pytorch=2.1.0.dev20230313+cu117
5+
#ARG torchvision=0.15.0.dev20230313+cu117
6+
#ARG torchaudio=2.0.0.dev20230313+cu117
7+
#ARG pytorch_lightning=1.9.3
8+
#ARG pycyda=11.7
69
ARG py=3.9
710
ARG pytorch=1.13.1
811
ARG torchvision=0.14.1
912
ARG torchaudio=0.13.1
10-
ARG pytorch_lightning=1.9.0
13+
ARG pytorch_lightning=1.9.3
1114
ARG pycyda=11.7
1215

16+
17+
ARG HOME=/home/aloception
18+
1319
ENV TZ=Europe/Paris
1420
ENV DEBIAN_FRONTEND=noninteractive
1521

16-
RUN apt-get update
22+
RUN apt-get -y update; apt-get -y install sudo
23+
1724
RUN apt-get install -y build-essential nano git wget libgl1-mesa-glx
1825

19-
# Usefull for scipy
20-
RUN apt-get install -y gfortran
21-
# required for aloscene
22-
RUN apt-get install -y libglib2.0-0
26+
# Usefull for scipy / required for aloscene
27+
RUN apt-get install -y gfortran libglib2.0-0
28+
29+
# Create aloception user
30+
RUN useradd --create-home --uid 1000 --shell /bin/bash aloception && usermod -aG sudo aloception && echo "aloception ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
2331

32+
ENV HOME /home/aloception
33+
WORKDIR /home/aloception
2434

25-
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
26-
RUN bash Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda
27-
ENV PATH=$PATH:/miniconda/condabin:/miniconda/bin
35+
36+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
37+
/bin/bash /tmp/miniconda.sh -b -p /opt/miniconda && \
38+
rm /tmp/miniconda.sh
39+
ENV CONDA_HOME /opt/miniconda
40+
ENV PATH ${CONDA_HOME}/condabin:${CONDA_HOME}/bin:${PATH}
2841
RUN /bin/bash -c "source activate base"
29-
ENV HOME /workspace
30-
WORKDIR /workspace
42+
43+
# The following so that any user can install packages inside this Image
44+
RUN chmod -R o+w /opt/miniconda && chmod -R o+w /home/aloception
45+
46+
USER aloception
3147

3248
# Pytorch & pytorch litning
49+
#RUN conda install py pytorch-cuda=${pycuda} -c pytorch -c nvidia
50+
#RUN pip install --pre torch==${pytorch} torchvision==${torchvision} torchaudio==${torchaudio} --index-url https://download.pytorch.org/whl/nightly/cu117
51+
#RUN pip install pytorch_lightning==${pytorch_lightning}
3352
RUN conda install pytorch==${pytorch} torchvision==${torchvision} torchaudio==${torchaudio} pytorch-cuda=${pycuda} -c pytorch -c nvidia
3453
RUN pip install pytorch_lightning==${pytorch_lightning}
3554

36-
COPY requirements-torch1.13.1.txt /install/requirements-torch1.13.1.txt
37-
RUN pip install -r /install/requirements-torch1.13.1.txt
55+
56+
COPY --chown=aloception:aloception requirements/requirements-torch1.13.1.txt /home/aloception/install/requirements-torch1.13.1.txt
57+
RUN pip install -r /home/aloception/install/requirements-torch1.13.1.txt
58+
COPY --chown=aloception:aloception ./aloscene/utils /home/aloception/install/utils
59+
60+
USER root
61+
COPY entrypoint.sh /entrypoint.sh
62+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<a href="https://visual-behavior.github.io/aloception-oss/">Documentation</a>
66

7-
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-0.5.1-green.svg)](https://conventionalcommits.org)
7+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-0.6.0-green.svg)](https://conventionalcommits.org)
88

99
# Aloception open source software
1010

@@ -78,17 +78,17 @@ training pipelines with **augmented tensors**.
7878
### Docker install
7979

8080
```
81-
docker build -t aloception-oss:cuda-11.3.1-pytorch1.13.1-lightning1.9.0 .
81+
docker build -t aloception-oss:cuda-11.3-pytorch1.13.1-lightning1.9.3 .
8282
```
8383

8484
```
85-
docker run --gpus all -it -v /YOUR/WORKSPACE/:/workspace --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix aloception-oss:cuda-11.3.1-pytorch1.13.1-lightning1.9.0
85+
docker run -e LOCAL_USER_ID=$(id -u) --gpus all -it -v /YOUR/WORKSPACE/:/workspace --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix aloception-oss:cuda-11.3-pytorch1.13.1-lightning1.9.3
8686
```
8787

8888
Or without building the image
8989

9090
```
91-
docker run --gpus all -it -v /YOUR/WORKSPACE/:/workspace --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix visualbehaviorofficial/aloception-oss:cuda-11.3.1-pytorch1.13.1-lightning1.9.0
91+
docker run -e LOCAL_USER_ID=$(id -u) --gpus all -it -v /YOUR/WORKSPACE/:/workspace --privileged -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix visualbehaviorofficial/aloception-oss:cuda-11.3-pytorch1.13.1-lightning1.9.3
9292
```
9393

9494

alodataset/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from . import utils
2+
from . import prepare
13
from .base_dataset import BaseDataset, Split
24
from .sequence_mixin import SequenceMixin
35
from .split_mixin import SplitMixin
@@ -17,3 +19,6 @@
1719
from .from_directory_dataset import FromDirectoryDataset
1820
from .woodScape_dataset import WooodScapeDataset
1921
from .woodScape_split_dataset import WoodScapeSplitDataset
22+
23+
import pkg_resources
24+
__version__ = pkg_resources.get_distribution("aloception").version

alodataset/io/__init__.py

Whitespace-only changes.

alodataset/prepare/__init__.py

Whitespace-only changes.

alodataset/utils/__init__.py

Whitespace-only changes.

alonet/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010

1111
from . import detr_panoptic
1212
from . import deformable_detr_panoptic
13+
14+
import pkg_resources
15+
__version__ = pkg_resources.get_distribution("aloception").version

alonet/common/base_datamodule.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import pytorch_lightning as pl
2+
import alonet
3+
import torch
4+
from torch.utils.data.sampler import RandomSampler, SequentialSampler
5+
6+
7+
class BaseDataModule(pl.LightningDataModule):
8+
"""
9+
Base class for all data modules.
10+
"""
11+
12+
def __init__(
13+
self, args, **kwargs,
14+
):
15+
super().__init__()
16+
alonet.common.pl_helpers.params_update(self, args, kwargs)
17+
18+
@staticmethod
19+
def add_argparse_args(parent_parser):
20+
parser = parent_parser.add_argument_group("BaseDataModule")
21+
parser.add_argument("--batch_size", type=int, default=5, help="Batch size (Default: %(default)s)")
22+
parser.add_argument(
23+
"--num_workers", type=int, default=8, help="num_workers to use on the dataset (Default: %(default)s)"
24+
)
25+
parser.add_argument("--sequential_sampler", action="store_true", help="sample data sequentially (no shuffle)")
26+
parser.add_argument(
27+
"--sample", action="store_true", help="Download a sample for train/val process (Default: %(default)s)"
28+
)
29+
parser.add_argument("--train_on_val", action="store_true", help="Train on validation set (Default: %(default)s)")
30+
31+
parser.add_argument("--no_aug", action="store_true", help="Disable data augmentation (Default: %(default)s)")
32+
return parent_parser
33+
34+
@property
35+
def train_dataset(self):
36+
if not hasattr(self, "_train_dataset"):
37+
self.setup()
38+
return self._train_dataset
39+
40+
@train_dataset.setter
41+
def train_dataset(self, new_dataset):
42+
self._train_dataset = new_dataset
43+
44+
@property
45+
def val_dataset(self):
46+
if not hasattr(self, "_val_dataset"):
47+
self.setup()
48+
return self._val_dataset
49+
50+
@val_dataset.setter
51+
def val_dataset(self, new_dataset):
52+
self._val_dataset = new_dataset
53+
54+
@property
55+
def test_dataset(self):
56+
if not hasattr(self, "_test_dataset"):
57+
self.setup()
58+
return self._test_dataset
59+
60+
@test_dataset.setter
61+
def test_dataset(self, new_dataset):
62+
self._test_dataset = new_dataset
63+
64+
def train_transform(self, frames, **kwargs):
65+
"""
66+
A structure to select the train transform function.
67+
Parameters
68+
----------
69+
frames : aloscene.Frame
70+
Input frames
71+
Returns
72+
-------
73+
aloscene.Frame
74+
"""
75+
if self.no_aug:
76+
return self._train_transform_no_aug(frames)
77+
else:
78+
return self._train_transform_aug(frames, **kwargs)
79+
80+
def _train_transform_no_aug(self, frames):
81+
"""
82+
Train_transform with no data augmentation.
83+
Parameters
84+
----------
85+
frames : aloscene.Frame
86+
Input frames
87+
Returns
88+
-------
89+
aloscene.Frame
90+
"""
91+
92+
raise NotImplementedError("Should be implemented in child class.")
93+
94+
def _train_transform_aug(self, frames):
95+
"""
96+
Train_transform with data augmentation.
97+
Parameters
98+
----------
99+
frames : aloscene.Frame
100+
Input frames
101+
Returns
102+
-------
103+
aloscene.Frame
104+
"""
105+
106+
raise NotImplementedError("Should be implemented in child class.")
107+
108+
def val_transform(self, frames, **kwargs):
109+
"""
110+
Val transform.
111+
Parameters
112+
----------
113+
frames : aloscene.Frame
114+
Input frames
115+
Returns
116+
-------
117+
aloscene.Frame
118+
"""
119+
120+
raise NotImplementedError("Should be implemented in child class.")
121+
122+
def setup(self, stage=None):
123+
""":attr:`train_dataset`, :attr:`val_dataset`, attr:`test_dataset` datasets setup
124+
Parameters
125+
----------
126+
stage : str, optional
127+
Stage either `fit`, `validate`, `test` or `predict`, by default None"""
128+
129+
raise NotImplementedError("Should be implemented in child class.")
130+
131+
def train_dataloader(self, sampler: torch.utils.data = None):
132+
"""Get train dataloader
133+
Parameters
134+
----------
135+
sampler : torch.utils.data, optional
136+
Sampler to load batches, by default None
137+
Returns
138+
-------
139+
torch.utils.data.DataLoader
140+
Dataloader for training process
141+
"""
142+
if sampler is None:
143+
sampler = RandomSampler if not self.sequential_sampler else SequentialSampler
144+
145+
return self.train_dataset.train_loader(batch_size=self.batch_size, num_workers=self.num_workers, sampler=sampler)
146+
147+
def val_dataloader(self, sampler: torch.utils.data = None):
148+
"""Get val dataloader
149+
Parameters
150+
----------
151+
sampler : torch.utils.data, optional
152+
Sampler to load batches, by default None
153+
Returns
154+
-------
155+
torch.utils.data.DataLoader
156+
Dataloader for validation process
157+
"""
158+
if sampler is None:
159+
sampler = SequentialSampler
160+
161+
return self.val_dataset.train_loader(batch_size=self.batch_size, num_workers=self.num_workers, sampler=sampler)
162+
163+
def test_dataloader(self, sampler: torch.utils.data = None):
164+
"""Get test dataloader
165+
Parameters
166+
----------
167+
sampler : torch.utils.data, optional
168+
Sampler to load batches, by default None
169+
Returns
170+
-------
171+
torch.utils.data.DataLoader
172+
Dataloader for inference process
173+
"""
174+
if sampler is None:
175+
sampler = SequentialSampler
176+
177+
return self.test_dataset.train_loader(batch_size=self.batch_size, num_workers=self.num_workers, sampler=sampler)

0 commit comments

Comments
 (0)