-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
796 additions
and
94 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
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,23 @@ | ||
name: Publish Docker image | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to GitHub Packages | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Login to Github Container Registry | ||
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Build image | ||
run: | | ||
docker build | ||
-f docker/Dockerfile | ||
--tag ghcr.io/albumentations-team/autoalbument:${{ github.event.release.tag_name }} | ||
--tag ghcr.io/albumentations-team/autoalbument:latest | ||
. | ||
- name: Push image | ||
run: docker push ghcr.io/albumentations-team/autoalbument |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.1" | ||
__version__ = "0.2.0" |
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
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,59 @@ | ||
from typing import Tuple | ||
|
||
import segmentation_models_pytorch as smp | ||
import timm | ||
from torch import nn, Tensor | ||
from torch.nn import Flatten | ||
|
||
|
||
class BaseDiscriminator(nn.Module): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__() | ||
|
||
def forward(self, input: Tensor) -> Tuple[Tensor, Tensor]: | ||
raise NotImplementedError | ||
|
||
|
||
class ClassificationModel(BaseDiscriminator): | ||
def __init__(self, architecture, pretrained, num_classes): | ||
super().__init__() | ||
self.base_model = timm.create_model(architecture, pretrained=pretrained) | ||
self.base_model.reset_classifier(num_classes) | ||
self.classifier = self.base_model.get_classifier() | ||
num_features = self.classifier.in_features | ||
self.discriminator = nn.Sequential( | ||
nn.Linear(num_features, num_features), nn.ReLU(), nn.Linear(num_features, 1) | ||
) | ||
|
||
def forward(self, input: Tensor) -> Tuple[Tensor, Tensor]: | ||
x = self.base_model.forward_features(input) | ||
x = self.base_model.global_pool(x).flatten(1) | ||
return self.classifier(x), self.discriminator(x).view(-1) | ||
|
||
|
||
class SemanticSegmentationModel(BaseDiscriminator): | ||
def __init__(self, architecture, encoder_architecture, num_classes, pretrained): | ||
super().__init__() | ||
model = getattr(smp, architecture) | ||
|
||
self.base_model = model( | ||
encoder_architecture, encoder_weights=self._get_encoder_weights(pretrained), classes=num_classes | ||
) | ||
num_features = self.base_model.encoder.out_channels[-1] | ||
self.base_model.classification_head = nn.Sequential( | ||
nn.AdaptiveAvgPool2d(1), | ||
Flatten(), | ||
nn.Linear(num_features, num_features), | ||
nn.ReLU(), | ||
nn.Linear(num_features, 1), | ||
) | ||
|
||
@staticmethod | ||
def _get_encoder_weights(pretrained): | ||
if isinstance(pretrained, bool): | ||
return "imagenet" if pretrained else None | ||
return pretrained | ||
|
||
def forward(self, input: Tensor) -> Tuple[Tensor, Tensor]: | ||
mask, discriminator_output = self.base_model(input) | ||
return mask, discriminator_output.view(-1) |
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,18 @@ | ||
FROM pytorch/pytorch:1.7.0-cuda11.0-cudnn8-runtime | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
libgl1-mesa-glx \ | ||
libglib2.0-0 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN useradd --create-home --shell /bin/bash --no-log-init autoalbument | ||
USER autoalbument | ||
ENV PATH="/home/autoalbument/.local/bin:${PATH}" | ||
WORKDIR /opt/autoalbument | ||
COPY . . | ||
RUN pip install --no-cache-dir . | ||
COPY docker/entrypoint.sh entrypoint.sh | ||
|
||
WORKDIR /autoalbument | ||
|
||
ENTRYPOINT ["/opt/autoalbument/entrypoint.sh"] |
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,3 @@ | ||
#!/bin/bash | ||
|
||
autoalbument-search --config-dir /config "$@" |
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.