Skip to content

Commit

Permalink
Fix remote paths. Updated Dockerfile and build image action (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
almazgimaev authored Jun 19, 2024
1 parent 313e20b commit ba11701
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@ on:
workflow_dispatch:
inputs:
tag_version:
description: "Docker Image Tag"
description: 'Docker Image Tag (without "v")'
required: true
default: ""

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get repository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
push: true
file: docker/Dockerfile
tags: supervisely/${{ env.REPOSITORY_NAME }}:${{ github.event.inputs.tag_version }}
tags: supervisely/embeddings_app:${{ github.event.inputs.tag_version }}
3 changes: 2 additions & 1 deletion _legacy/calculate_embeddings/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def infer_one(image, labels, instance_mode):
json.dump(cfg, f)
torch.save(embeddings, save_paths["embeddings"])
print("uploading to team_files...")
api.file.upload_bulk(team_id, list(save_paths.values()), list(save_paths.values()))
remote_paths = [f"/{p}" for p in list(save_paths.values())]
api.file.upload_bulk(team_id, list(save_paths.values()), remote_paths)

print("result shape:", embeddings.shape)
print("done")
3 changes: 2 additions & 1 deletion _legacy/visualize_embeddings/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def calculate_projections(projection_method, metric="euclidean", umap_min_dist=0
)
torch.save(projections, save_paths["projections"])
print("uploading projections to team_files...")
api.file.upload(team_id, save_paths["projections"], save_paths["projections"])
remote_path = f"/{save_paths['projections']}"
api.file.upload(team_id, save_paths["projections"], remote_path)


obj_classes = list(set(all_info["object_cls"]))
Expand Down
10 changes: 5 additions & 5 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
supervisely
transformers
timm
supervisely==6.72.134
transformers==4.33.2
timm==0.9.5
torch
scikit-learn
umap-learn
scikit-learn==1.3.1
umap-learn==0.5.4
9 changes: 7 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM supervisely/clip_filtering:1.0.2
FROM supervisely/base-py-sdk:6.73.90


ENV DEBIAN_FRONTEND=noninteractive

RUN pip3 install torch==1.11.0+cu113 torchvision==0.12.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113


RUN pip3 install transformers==4.33.2 timm==0.9.5 scikit-learn==1.3.1 umap-learn==0.5.4
RUN pip3 install supervisely==6.72.134
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,15 @@ def run():
projections = run_utils.calculate_projections(embeddings, all_info_list, projection_method, metric=metric)
print("uploading projections to team_files...")
torch.save(projections, save_paths["projections"])
api.file.upload(team_id, save_paths["projections"], save_paths["projections"])
remote_path = f"/{save_paths['projections']}"
api.file.upload(team_id, save_paths["projections"], remote_path)
file_id = str(api.file.get_info_by_path(team_id, "/" + save_paths["embeddings"]).id)
server_address = os.environ.get("SERVER_ADDRESS")
if server_address:
url = f"{server_address}/files/{file_id}"
if sly.is_development():
url = sly.utils.abs_url(f"files/{file_id}")
else:
url = f"/files/{file_id}"
info_run.description += f"all was saved to team_files: <a href={url}>{save_paths['embeddings']}</a><br>"

# 6. Show chart
Expand Down
3 changes: 2 additions & 1 deletion src/run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def upload_embeddings(embeddings, info_updated, cfg, api, path_prefix, save_path
with open(save_paths["cfg"], "w") as f:
json.dump(cfg, f)
torch.save(embeddings, save_paths["embeddings"])
api.file.upload_bulk(team_id, list(save_paths.values()), list(save_paths.values()))
remote_paths = [f"/{p}" for p in list(save_paths.values())]
api.file.upload_bulk(team_id, list(save_paths.values()), remote_paths)


def download_embeddings(api, path_prefix, save_paths, team_id):
Expand Down

0 comments on commit ba11701

Please sign in to comment.