Skip to content

Commit

Permalink
Merge pull request #10 from chvvkumar/dev
Browse files Browse the repository at this point in the history
Add ability to provide a custom model file and labels file to the container via bind mounts on the docker host. This allows the user to supply their own trained model and classification labels instead of using the example model in this repo.
  • Loading branch information
chvvkumar authored Dec 16, 2024
2 parents 7c53fe6 + eb44cc5 commit b2f2ec7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ WORKDIR /app
COPY requirements.txt .

# Install the dependencies
RUN pip install -U pip & pip install --no-cache-dir -r requirements.txt
RUN pip install -U pip && pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code into the container
COPY . .
# Copy the rest of the application code into the container, excluding keras_model.h5 and labels.txt
COPY convert.py detect.py ./

# Run convert.py first, then detect.py
CMD ["sh", "-c", "python convert.py && python detect.py"]
6 changes: 4 additions & 2 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

# Define parameters
image_url = os.environ['IMAGE_URL']
model_path = os.getenv('MODEL_PATH', 'keras_model.h5')
label_path = os.getenv('LABEL_PATH', 'labels.txt')
broker = os.environ['MQTT_BROKER']
port = int(os.getenv("MQTT_PORT"))
topic = os.environ['MQTT_TOPIC']
detect_interval = int(os.environ['DETECT_INTERVAL'])

# Load the model and class names
model = load_model("keras_model.h5", compile=False) # Load the model
class_names = open("labels.txt", "r").readlines() # Load the class names
model = load_model(model_path, compile=False) # Load the model
class_names = open(label_path, "r").readlines() # Load the class names

# Clear the console
os.system('cls' if os.name == 'nt' else 'clear')
Expand Down
23 changes: 19 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Overcast

![](/images/Overcast.png)

## Docker (preferred method)
## Docker (preferred method, x86 only at the moment)

DEV Branch

Expand All @@ -31,6 +31,10 @@ Main branch

[![main](https://github.com/chvvkumar/simpleCloudDetect/actions/workflows/main.yml/badge.svg)](https://github.com/chvvkumar/simpleCloudDetect/actions/workflows/main.yml) ![Docker Image Size (latest)](https://img.shields.io/docker/image-size/chvvkumar/simpleclouddetect/latest?style=flat&logo=docker&logoSize=auto) ![](https://img.shields.io/docker/pulls/chvvkumar/simpleclouddetect?style=flat&logo=docker&label=Pulls)

CHANGES:
- 2024-11-20: Add ability to provide a custom model file and labels file to the container via bind mounts on the docker host. This allows the user to supply their own trained model and classification labels instead of using the example model in this repo.
- 2024-11-19: Add ability to use local images via https://github.com/chvvkumar/simpleCloudDetect/pull/8 .
- 2024-10-26: Initial release with basic cloud detection functionality.


docker run:
Expand All @@ -39,18 +43,22 @@ docker pull chvvkumar/simpleclouddetect:latest

# When using an image from a URL
docker run -d --name simple-cloud-detect --network=host \
-e IMAGE_URL="http://localhost/current/resized/image.jpg" \
-e IMAGE_URL="http://allskypi5.lan/current/resized/image.jpg" \
-e MQTT_BROKER="192.168.1.250" \
-e MQTT_PORT="1883" \
-e MQTT_TOPIC="Astro/SimpleCloudDetect" \
-e DETECT_INTERVAL="60" \
-v /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5 \
-v /docker/simpleclouddetect/labels.txt:/app/labels.txt \
chvvkumar/simpleclouddetect:latest
```
As an alternative you can mount the image as a volume and reference it with the `IMAGE_URL` environment variable:
```shell
# When using an image from a local file path
docker run -d --name simple-cloud-detect --network=host \
-v $HOME/path/to/image.jpg:/tmp/image.jpg
-v /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5 \
-v /docker/simpleclouddetect/labels.txt:/app/labels.txt \
-v $HOME/path/to/image.jpg:/tmp/image.jpg \
-e IMAGE_URL="file:///tmp/image.jpg" \
-e MQTT_BROKER="192.168.1.250" \
-e MQTT_PORT="1883" \
Expand All @@ -67,11 +75,15 @@ docker compose:
container_name: simple-cloud-detect
network_mode: host
environment:
- IMAGE_URL=http://localhost/current/resized/image.jpg
- IMAGE_URL=http://allskypi5.lan/current/resized/image.jpg
- MQTT_BROKER=192.168.1.250
- MQTT_PORT=1883
- MQTT_TOPIC=Astro/SimpleCloudDetect
- DETECT_INTERVAL=60
volumes:
- /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5
- /docker/simpleclouddetect/labels.txt:/app/labels.txt
restart: unless-stopped
image: chvvkumar/simpleclouddetect:latest

# When using an image from a local path
Expand All @@ -86,6 +98,9 @@ docker compose:
- DETECT_INTERVAL=60
volumes:
- '$HOME/path/to/image.jpg:/tmp/image.jpg'
- /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5
- /docker/simpleclouddetect/labels.txt:/app/labels.txt
restart: unless-stopped
image: chvvkumar/simpleclouddetect:latest
```
## Manual install and run Overview of operations
Expand Down

0 comments on commit b2f2ec7

Please sign in to comment.