Skip to content

Commit

Permalink
perf: bump to better indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
danellecline committed Sep 4, 2024
1 parent d68ce82 commit 7beb4b7
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ docs/site
# logs
src/app/logs/

src/submodules
src/submodules
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================================================
# Docker image for fastapi-vss
# ================================================================
FROM mbari/aidata:1.12.2
FROM mbari/aidata:1.17.0

LABEL vendor="MBARI"
LABEL maintainer="[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.cuda
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================================================
# Docker image for fastapi-vss (CUDA enabled)
# ================================================================
FROM mbari/aidata:1.12.2-cuda124
FROM mbari/aidata:1.17.0-cuda124

LABEL vendor="MBARI"
LABEL maintainer="[email protected]"
Expand Down
40 changes: 35 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ list:
# Setup the environment
install:
conda env create -f environment.yml
git submodule update --init --recursive
python -m pip install -r src/submodules/aidata/requirements.txt
git clone --branch v1.16.0 https://github.com/mbari-org/aidata ./src/aidata
python -m pip install -r src/aidata/requirements.txt
python -m pip install https://github.com/redis/redis-py/archive/refs/tags/v5.0.9.zip

# Update the conda environment. Run this command after checking out any code changes
update:
git submodule update --init --recursive
python -m pip install -r src/submodules/aidata/requirements.txt
conda env update --file environment.yml --prune
python -m pip install https://github.com/redis/redis-py/archive/refs/tags/v5.0.9.zip

Expand All @@ -35,7 +33,7 @@ run-server: kill-uvicorn
#!/usr/bin/env bash
echo "FastAPI server running at http://localhost:8002"
echo "FastAPI docs running at http://localhost:8002/docs"
export PYTHONPATH=$PWD/src:$PWD/src/submodules/aidata
export PYTHONPATH=$PWD/src:/Users/dcline/Dropbox/code/aidata
cd src/app && conda run -n fastapi-vss --no-capture-output uvicorn main:app --port 8002 --reload
run-server-prod: build-docker
Expand All @@ -50,6 +48,12 @@ build-docker:
tag=$(git describe --tags --always)
docker build -t mbari/fastapi-app:$tag .
# Build the CUDA Docker image
build-docker-cuda:
#!/usr/bin/env bash
tag=$(git describe --tags --always)
docker build -t mbari/fastapi-app:$tag -f Dockerfile.cuda .
build-docker-no-cache:
#!/usr/bin/env bash
tag=$(git describe --tags --always)
Expand All @@ -62,3 +66,29 @@ run-docker:
# Default recipe
default:
just run-server

test_all_ids:
#!/usr/bin/env bash
curl -X 'POST' \
'http://localhost:8002/ids/i2map' \
-H 'accept: application/json' \
-d ''
process_copepods:
#!/usr/bin/env bash
cd ./tests/images/copepod
curl -X 'POST' \
'http:/localhost:8002/knn/3/i2map' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/png'
curl -X 'POST' \
'http:/localhost:8002/knn/3/i2map' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/png'
curl -X 'POST' \
'http:/localhost:8002/knn/3/i2map' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/png'
19 changes: 17 additions & 2 deletions src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ async def root():
async def get_projects():
return {"projects": list(global_config.keys())}

@app.post("/ids/{project}", status_code=status.HTTP_200_OK)
async def get_ids(project: str = DEFAULT_PROJECT):
# Check if the project name is in the config
if project not in global_config.keys():
return {"error": f"Invalid project name {project}"}

v = global_config[project]['v']
try:
classes, ids = v.get_ids()
return {"ids": ids, "classes": classes}
except Exception as e:
return {"error": f"Error getting ids: {e}"}

@app.post("/knn/{top_n}/{project}", status_code=status.HTTP_200_OK)
async def knn(files: List[UploadFile] = File(...), top_n: int = 1, project: str = DEFAULT_PROJECT):
Expand All @@ -56,5 +68,8 @@ async def knn(files: List[UploadFile] = File(...), top_n: int = 1, project: str

v = global_config[project]['v']
images = [f.file for f in files]
predictions, scores = v.predict(images, top_n)
return {"predictions": predictions, "scores": scores}
try:
predictions, scores, ids = v.predict(images, top_n)
return {"predictions": predictions, "scores": scores, "ids": ids}
except Exception as e:
return {"error": f"Error predicting images: {e}"}
56 changes: 56 additions & 0 deletions src/app/project/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Config file for 902111-CFE project
redis:
host: "doris.shore.mbari.org"
port: 6382

data:
raw_data_path: "/mnt/CFElab/"
processed_path: "/mnt/ML_SCRATCH/902111-CFE"
version: "Baseline"
labels: "copepod"
download_args: ["--verified"]

sdcat:
model: "hustvl/yolos-tiny"
clu_det_ini: "sdcat_clu_det.ini"
exemplar_ini: "sdcat_exemplar.ini"

vss:
project: "cfe"
threshold: 0.4

tator:
project: "902111-CFE"
host: "mantis.shore.mbari.org"
bulk_url: "http://mantis.shore.mbari.org:8001/label/id"

image:
attributes:
iso_datetime:
type: string
depth:
type: int

box:
attributes:
Label:
type: string
concept:
type: string
score:
type: float
cluster:
type: string
saliency:
type: float
group:
type: string
obs_uuid:
type: string
exemplar:
type: bool
verified:
type: bool


ffmpeg_path: "/usr/bin/ffmpeg"
Binary file added tests/images/copepod/copepod1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/copepod/copepod2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/copepod/copepod3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7beb4b7

Please sign in to comment.