-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IHP-24] Recognition docker container (#26)
- Loading branch information
1 parent
f56c4c8
commit 9ba7f42
Showing
16 changed files
with
272 additions
and
90 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,63 @@ | ||
name: publish resizer | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
paths: | ||
- 'recognizer/**' | ||
- 'domain/**' | ||
- 'common/**' | ||
- 'project/**' | ||
- 'build.sbt' | ||
- '.github/**' | ||
|
||
env: | ||
IMAGE_NAME: image-hosting-processing-recognizer | ||
|
||
jobs: | ||
publish-container: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Log in to registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
|
||
- name: set up JDK 17 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 17 | ||
|
||
#- name: run tests | ||
# run: sbt test | ||
|
||
#- name: run integration tests | ||
# run: sbt it:test | ||
|
||
- name: Assembly | ||
run: sbt buildRecognizer | ||
|
||
- name: Build image | ||
run: docker build ./recognizer --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# make version be equal to branch name (in case we want to have several branches to push container) | ||
VERSION=$GITHUB_REF_NAME | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
addCommandAlias("buildResizer", "project resizer;assembly;") | ||
addCommandAlias("buildRecognizer", "project recognizer;assembly;") |
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,10 @@ | ||
FROM eclipse-temurin:17-jre-jammy | ||
|
||
WORKDIR /opt/app | ||
|
||
COPY ./target/scala-2.13/image-hosting-processing-recognizer-assembly-0.1.0-SNAPSHOT.jar ./app.jar | ||
|
||
# subfolder to mount nsfw model and synset here | ||
RUN mkdir /opt/app/nsfw | ||
|
||
ENTRYPOINT ["java", "-cp", "app.jar", "com.github.baklanovsoft.imagehosting.recognizer.Main"] |
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,11 @@ | ||
#docker buildx build --platform linux/amd64 -t test/recognizer . | ||
|
||
cd .. | ||
|
||
sbt buildRecognizer | ||
|
||
cd recognizer | ||
|
||
docker build -t test/recognizer . | ||
|
||
docker image ls | grep test/recognizer |
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 transformers import AutoImageProcessor, AutoModelForImageClassification | ||
import torch | ||
from PIL import Image | ||
from transformers import AutoTokenizer | ||
|
||
model_name = "DenisNovac/nsfw_image_detection" | ||
|
||
model = AutoModelForImageClassification.from_pretrained(model_name, torchscript=True, return_dict=False) | ||
|
||
processor = AutoImageProcessor.from_pretrained(model_name) | ||
|
||
image = Image.open("images/hentai.jpg") | ||
image_inputs = processor(images=image, return_tensors="pt") | ||
|
||
config = {'forward': [image_inputs['pixel_values']]} | ||
converted = torch.jit.trace_module(model, config) | ||
|
||
torch.jit.save(converted, "nsfw_model.pt") |
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,3 +1,3 @@ | ||
# https://huggingface.co/DenisNovac/nsfw_image_detection | ||
# fork of https://huggingface.co/Falconsai/nsfw_image_detection | ||
wget -O converted-to-torchscript.pt https://huggingface.co/DenisNovac/nsfw_image_detection/resolve/main/converted-to-torchscript.pt?download=true | ||
wget -O nsfw_model.pt https://huggingface.co/DenisNovac/nsfw_image_detection/resolve/main/converted-to-torchscript.pt?download=true |
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
Oops, something went wrong.