-
Notifications
You must be signed in to change notification settings - Fork 261
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
5 changed files
with
39 additions
and
55 deletions.
There are no files selected for viewing
31 changes: 20 additions & 11 deletions
31
label_studio_ml/examples/segment_anything_model/Dockerfile
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,21 +1,30 @@ | ||
FROM python:3.8-slim | ||
FROM python:3.8-slim-buster | ||
|
||
WORKDIR /app | ||
|
||
ENV PYTHONUNBUFFERED=True \ | ||
PORT=9090 | ||
|
||
PORT=9090 \ | ||
MODEL_DIR=/data/models \ | ||
VITH_CHECKPOINT=/app/models/sam_vit_h_4b8939.pth \ | ||
MOBILESAM_CHECKPOINT=/app/models/mobile_sam.pt \ | ||
ONNX_CHECKPOINT=/app/models/sam_onnx_quantized_example.onnx | ||
|
||
RUN apt-get update -q \ | ||
&& apt-get install -qy --no-install-recommends wget git libopencv-dev python3-opencv \ | ||
&& apt-get autoremove -y \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy and run the model download script | ||
COPY download_models.sh . | ||
RUN bash /app/download_models.sh | ||
|
||
# Install Python dependencies | ||
COPY requirements.txt . | ||
|
||
RUN apt-get update && apt-get install -y wget git python3-opencv \ | ||
&& pip install --no-cache-dir -r requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . ./ | ||
|
||
# Make the start.sh script executable | ||
RUN chmod +x /app/start.sh | ||
|
||
EXPOSE 9090 | ||
|
||
# Set the start.sh script as the entrypoint | ||
ENTRYPOINT ["/app/start.sh"] | ||
CMD ["/app/start.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
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
25 changes: 17 additions & 8 deletions
25
label_studio_ml/examples/segment_anything_model/download_models.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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# Make sure the models directory exists | ||
mkdir -p models | ||
MODELS_DIR="models" | ||
mkdir -p ${MODELS_DIR} | ||
|
||
# check if file `sam_vit_h_4b8939.pth` exists, otherwise download the model | ||
[ -f models/sam_vit_h_4b8939.pth ] || | ||
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth -P models/ | ||
download_model() { | ||
FILE_PATH="${MODELS_DIR}/$1" | ||
URL="$2" | ||
|
||
# check if file `mobile_sam.pt` exists, otherwise download the model | ||
[ -f models/mobile_sam.pt ] || | ||
wget https://github.com/ChaoningZhang/MobileSAM/raw/master/weights/mobile_sam.pt -P models/ | ||
if [ ! -f "${FILE_PATH}" ]; then | ||
wget -q "${URL}" -P ${MODELS_DIR}/ | ||
fi | ||
} | ||
|
||
# Model files and their corresponding URLs | ||
declare -A MODELS | ||
MODELS["sam_vit_h_4b8939.pth"]="https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth" | ||
MODELS["mobile_sam.pt"]="https://github.com/ChaoningZhang/MobileSAM/raw/master/weights/mobile_sam.pt" | ||
|
||
for model in "${!MODELS[@]}"; do | ||
download_model "${model}" "${MODELS[${model}]}" | ||
done |
18 changes: 2 additions & 16 deletions
18
label_studio_ml/examples/segment_anything_model/start.sh
100644 → 100755
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