From fb25acf05210b5572e1f30902cb31e8d0a09a593 Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 01:46:42 -0600 Subject: [PATCH 1/7] Add ability to load model file from host path --- Dockerfile | 2 +- detect.py | 3 ++- readme.md | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7d01d31..b204995 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ 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 . . diff --git a/detect.py b/detect.py index b3751c1..ae476cd 100644 --- a/detect.py +++ b/detect.py @@ -13,13 +13,14 @@ # Define parameters image_url = os.environ['IMAGE_URL'] +model_path = os.getenv('MODEL_PATH', 'keras_model.h5') 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 +model = load_model(model_path, compile=False) # Load the model class_names = open("labels.txt", "r").readlines() # Load the class names # Clear the console diff --git a/readme.md b/readme.md index f0b0d2d..f511bab 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,7 @@ docker run -d --name simple-cloud-detect --network=host \ -e MQTT_PORT="1883" \ -e MQTT_TOPIC="Astro/SimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ + -e MODEL_PATH="/path/on/host/keras_model.h5" \ chvvkumar/simpleclouddetect:latest ``` As an alternative you can mount the image as a volume and reference it with the `IMAGE_URL` environment variable: @@ -56,6 +57,7 @@ docker run -d --name simple-cloud-detect --network=host \ -e MQTT_PORT="1883" \ -e MQTT_TOPIC="Astro/SimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ + -e MODEL_PATH="/path/on/host/keras_model.h5" \ chvvkumar/simpleclouddetect:latest ``` @@ -72,6 +74,7 @@ docker compose: - MQTT_PORT=1883 - MQTT_TOPIC=Astro/SimpleCloudDetect - DETECT_INTERVAL=60 + - /path/on/host/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 image: chvvkumar/simpleclouddetect:latest # When using an image from a local path @@ -86,6 +89,7 @@ docker compose: - DETECT_INTERVAL=60 volumes: - '$HOME/path/to/image.jpg:/tmp/image.jpg' + - /path/on/host/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 image: chvvkumar/simpleclouddetect:latest ``` ## Manual install and run Overview of operations From 33b89cc46be524b405dc9da87bfa3ab4457d6133 Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 01:56:10 -0600 Subject: [PATCH 2/7] Update README to reflect new model path for Docker configuration --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index f511bab..4c3fe9a 100644 --- a/readme.md +++ b/readme.md @@ -44,7 +44,7 @@ docker run -d --name simple-cloud-detect --network=host \ -e MQTT_PORT="1883" \ -e MQTT_TOPIC="Astro/SimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ - -e MODEL_PATH="/path/on/host/keras_model.h5" \ + -e MODEL_PATH="/docker/simpleclouddetect/keras_model.h5" \ chvvkumar/simpleclouddetect:latest ``` As an alternative you can mount the image as a volume and reference it with the `IMAGE_URL` environment variable: @@ -57,7 +57,7 @@ docker run -d --name simple-cloud-detect --network=host \ -e MQTT_PORT="1883" \ -e MQTT_TOPIC="Astro/SimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ - -e MODEL_PATH="/path/on/host/keras_model.h5" \ + -e MODEL_PATH="/docker/simpleclouddetect/keras_model.h5" \ chvvkumar/simpleclouddetect:latest ``` @@ -74,7 +74,7 @@ docker compose: - MQTT_PORT=1883 - MQTT_TOPIC=Astro/SimpleCloudDetect - DETECT_INTERVAL=60 - - /path/on/host/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 + - /docker/simpleclouddetect/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 image: chvvkumar/simpleclouddetect:latest # When using an image from a local path @@ -89,7 +89,7 @@ docker compose: - DETECT_INTERVAL=60 volumes: - '$HOME/path/to/image.jpg:/tmp/image.jpg' - - /path/on/host/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 + - /docker/simpleclouddetect/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 image: chvvkumar/simpleclouddetect:latest ``` ## Manual install and run Overview of operations From a51dab3b7d2a29294d927c1ca0d962394ebe3496 Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 02:35:24 -0600 Subject: [PATCH 3/7] Refactor Dockerfile to copy specific files and update CMD; modify detect.py to use dynamic label path; enhance README with volume mounting instructions for model and labels --- Dockerfile | 4 ++-- detect.py | 3 ++- readme.md | 25 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index b204995..0dcf89b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ COPY requirements.txt . # Install the dependencies 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"] diff --git a/detect.py b/detect.py index ae476cd..13a5884 100644 --- a/detect.py +++ b/detect.py @@ -14,6 +14,7 @@ # 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'] @@ -21,7 +22,7 @@ # Load the model and class names model = load_model(model_path, compile=False) # Load the model -class_names = open("labels.txt", "r").readlines() # Load the class names +class_names = open(label_path, "r").readlines() # Load the class names # Clear the console os.system('cls' if os.name == 'nt' else 'clear') diff --git a/readme.md b/readme.md index 4c3fe9a..43a9a05 100644 --- a/readme.md +++ b/readme.md @@ -39,25 +39,27 @@ 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 MQTT_TOPIC="Astro/FEATURESimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ - -e MODEL_PATH="/docker/simpleclouddetect/keras_model.h5" \ - chvvkumar/simpleclouddetect:latest + -v /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5 \ + -v /docker/simpleclouddetect/labels.txt:/app/labels.txt \ + simpleclouddetect:feature_custommodelfile ``` 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" \ -e MQTT_TOPIC="Astro/SimpleCloudDetect" \ -e DETECT_INTERVAL="60" \ - -e MODEL_PATH="/docker/simpleclouddetect/keras_model.h5" \ chvvkumar/simpleclouddetect:latest ``` @@ -69,12 +71,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 - - /docker/simpleclouddetect/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 + 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 @@ -89,7 +94,9 @@ docker compose: - DETECT_INTERVAL=60 volumes: - '$HOME/path/to/image.jpg:/tmp/image.jpg' - - /docker/simpleclouddetect/keras_model.h5:/docker/simpleclouddetect/keras_model.h5 + - /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 From 80b4645236f0809bb29ed68758b825e4841f005a Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 02:54:08 -0600 Subject: [PATCH 4/7] Update README to include change log for custom model and local image support --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 43a9a05..58df0d7 100644 --- a/readme.md +++ b/readme.md @@ -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: From 1c06218e644bb4d835d5769ebd3fe248eb58c145 Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 03:02:46 -0600 Subject: [PATCH 5/7] Update Docker image reference in README to use latest version --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 58df0d7..1225d6e 100644 --- a/readme.md +++ b/readme.md @@ -50,7 +50,7 @@ docker run -d --name simple-cloud-detect --network=host \ -e DETECT_INTERVAL="60" \ -v /docker/simpleclouddetect/keras_model.h5:/app/keras_model.h5 \ -v /docker/simpleclouddetect/labels.txt:/app/labels.txt \ - simpleclouddetect:feature_custommodelfile + chvvkumar/simpleclouddetect:latest ``` As an alternative you can mount the image as a volume and reference it with the `IMAGE_URL` environment variable: ```shell From ced5ac8a6367d4c4672a31e8193145734119df9d Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Wed, 20 Nov 2024 03:05:17 -0600 Subject: [PATCH 6/7] Update README to clarify Docker method is currently x86 only --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1225d6e..c3ce9c0 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ Overcast ![](/images/Overcast.png) -## Docker (preferred method) +## Docker (preferred method, x86 only at the moment) DEV Branch From eb44cc56ed90e9f0227358dca48c1b09874ef18a Mon Sep 17 00:00:00 2001 From: chvvkumar Date: Thu, 21 Nov 2024 07:02:50 -0600 Subject: [PATCH 7/7] Fix typo in readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c3ce9c0..376b101 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,7 @@ docker run -d --name simple-cloud-detect --network=host \ -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/FEATURESimpleCloudDetect" \ + -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 \