diff --git a/.gitignore b/.gitignore index 30f1add..40be6fd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,13 @@ Images/** **/cmake_install.cmake **/CMakeCache.txt camera +CMakeFiles/** +**/.env +src/lfwa/** +**/__pycache__/** +src/model/message/__pycache__/** +src/model/__pycache__/utils.cpython-38.pyc +src/model/message/__pycache__/__init__.cpython-38.pyc +src/model/message/__pycache__/sms_message.cpython-38.pyc +**/Makefile src/lfwa/** diff --git a/Makefile b/Makefile deleted file mode 100644 index 5f611d3..0000000 --- a/Makefile +++ /dev/null @@ -1,192 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.13 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - - -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/local/bin/cmake - -# The command to remove a file. -RM = /usr/local/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/cds-nano-3/edge-ml - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/cds-nano-3/edge-ml - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/local/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." - /usr/local/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# The main all target -all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles /home/cds-nano-3/edge-ml/CMakeFiles/progress.marks - $(MAKE) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - $(MAKE) -f CMakeFiles/Makefile2 clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - $(MAKE) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - $(MAKE) -f CMakeFiles/Makefile2 preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -#============================================================================= -# Target rules for targets named camera - -# Build rule for target. -camera: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 camera -.PHONY : camera - -# fast build rule for target. -camera/fast: - $(MAKE) -f CMakeFiles/camera.dir/build.make CMakeFiles/camera.dir/build -.PHONY : camera/fast - -#============================================================================= -# Target rules for targets named UtilityLib - -# Build rule for target. -UtilityLib: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 UtilityLib -.PHONY : UtilityLib - -# fast build rule for target. -UtilityLib/fast: - $(MAKE) -f utils/CMakeFiles/UtilityLib.dir/build.make utils/CMakeFiles/UtilityLib.dir/build -.PHONY : UtilityLib/fast - -src/simple_camera.o: src/simple_camera.cpp.o - -.PHONY : src/simple_camera.o - -# target to build an object file -src/simple_camera.cpp.o: - $(MAKE) -f CMakeFiles/camera.dir/build.make CMakeFiles/camera.dir/src/simple_camera.cpp.o -.PHONY : src/simple_camera.cpp.o - -src/simple_camera.i: src/simple_camera.cpp.i - -.PHONY : src/simple_camera.i - -# target to preprocess a source file -src/simple_camera.cpp.i: - $(MAKE) -f CMakeFiles/camera.dir/build.make CMakeFiles/camera.dir/src/simple_camera.cpp.i -.PHONY : src/simple_camera.cpp.i - -src/simple_camera.s: src/simple_camera.cpp.s - -.PHONY : src/simple_camera.s - -# target to generate assembly for a file -src/simple_camera.cpp.s: - $(MAKE) -f CMakeFiles/camera.dir/build.make CMakeFiles/camera.dir/src/simple_camera.cpp.s -.PHONY : src/simple_camera.cpp.s - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... rebuild_cache" - @echo "... camera" - @echo "... edit_cache" - @echo "... UtilityLib" - @echo "... src/simple_camera.o" - @echo "... src/simple_camera.i" - @echo "... src/simple_camera.s" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/README.md b/README.md index eaa3603..2026649 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Make sure git-clang-format is installed with `npm install -g clang-format` 1. Call `clang-format.sh` under ci/ 2. `git add` and `git commit`! -To run: + +## To run `cd build` @@ -15,3 +16,15 @@ To run: `make` `./camera` + +## Setting up Twilio + +- `cd` to `src/message/` + +- Make a `.env` file with `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` set to your account SID and Auth Token + +- macOS: `brew tap twilio/brew && brew install twilio` + +- `twilio login` + +- `pip install twilio` diff --git a/camera b/camera deleted file mode 100755 index 982320b..0000000 Binary files a/camera and /dev/null differ diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 5a4e0c2..0000000 --- a/src/Makefile +++ /dev/null @@ -1,134 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.13 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - - -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/local/bin/cmake - -# The command to remove a file. -RM = /usr/local/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/cds-nano-3/edge-ml - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/cds-nano-3/edge-ml - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/local/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." - /usr/local/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# The main all target -all: cmake_check_build_system - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles /home/cds-nano-3/edge-ml/src/CMakeFiles/progress.marks - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/all - $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... rebuild_cache" - @echo "... edit_cache" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/src/model/Siamese_Network.py b/src/model/Siamese_Network.py index 4c515e6..f3e798d 100644 --- a/src/model/Siamese_Network.py +++ b/src/model/Siamese_Network.py @@ -1,10 +1,12 @@ +from sklearn.model_selection import train_test_split + import os import pickle import random import numpy as np import tensorflow as tf -from sklearn.model_selection import train_test_split + from tensorflow.keras import Input, Sequential, Model from tensorflow.keras import backend as K from tensorflow.keras.callbacks import EarlyStopping @@ -279,10 +281,10 @@ def evaluate(self, test_file, batch_size, analyze=False): def predict(self, x_test, names): prob = self.siamese_net.predict(x_test) - for pair_index in range(len(names)): - name = names[pair_index] - pair_prob = prob[pair_index][0] - print(f"Similar to {name} with probability: ", pair_prob) + name = names[0] + pair_prob = prob[0][0] + print(f"Similar to {name} with probability: ", pair_prob) + return pair_prob def _analyze(self, x_test, y_test, names): """ diff --git a/src/model/Siamese_Predictor.py b/src/model/Siamese_Predictor.py index 3bdbaae..f0d5998 100644 --- a/src/model/Siamese_Predictor.py +++ b/src/model/Siamese_Predictor.py @@ -1,3 +1,4 @@ +import sklearn import threading import tensorflow as tf from tensorflow.keras.optimizers import Adam @@ -14,6 +15,7 @@ import threading from Siamese_Network import SiameseNetwork from PIL import Image +from message import sms_message WIDTH = HEIGHT = 105 @@ -39,7 +41,6 @@ def preprocess_image(filename): return img - # load the model siamese = SiameseNetwork( seed=seed, @@ -66,7 +67,14 @@ def get_similarity_score(img_path): # add a dimension to the tensor # get embeddings - siamese.predict([david_2, david_1], ["David Han"]) + prob = siamese.predict([david_2, david_1], ["David Han"]) + # positive_similarity = cosine_similarity(anchor_embedding, positive_embedding) + # print(f"Similarity score for {img_path}: ", positive_similarity.numpy()) + print(f"Probability of David: {prob}", prob) + threshold = 0.8 + print("Sending message") + # sms_message.send_message(positive_similarity.numpy() < threshold) + sms_message.send_message(prob < threshold) # set up on created diff --git a/src/model/__pycache__/utils.cpython-38.pyc b/src/model/__pycache__/utils.cpython-38.pyc new file mode 100644 index 0000000..0a34ceb Binary files /dev/null and b/src/model/__pycache__/utils.cpython-38.pyc differ diff --git a/src/model/message/__init__.py b/src/model/message/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/model/message/__pycache__/__init__.cpython-38.pyc b/src/model/message/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..4f78ac3 Binary files /dev/null and b/src/model/message/__pycache__/__init__.cpython-38.pyc differ diff --git a/src/model/message/__pycache__/sms_message.cpython-38.pyc b/src/model/message/__pycache__/sms_message.cpython-38.pyc new file mode 100644 index 0000000..5e09d02 Binary files /dev/null and b/src/model/message/__pycache__/sms_message.cpython-38.pyc differ diff --git a/src/model/message/sms_message.py b/src/model/message/sms_message.py new file mode 100644 index 0000000..5504b71 --- /dev/null +++ b/src/model/message/sms_message.py @@ -0,0 +1,20 @@ +import os +from twilio.rest import Client +from dotenv import load_dotenv + +load_dotenv() + +account_sid = os.getenv('TWILIO_ACCOUNT_SID') +auth_token = os.getenv('TWILIO_AUTH_TOKEN') + +from_number = '+18886815709' +to_number = '+19788814542' + +def send_message(intruder_detected): + msg = "Intruder Alert!" if intruder_detected else "Welcome!" + client = Client(account_sid, auth_token) + message = client.messages.create( + body=msg, + from_=from_number, + to=to_number) + diff --git a/utils/Makefile b/utils/Makefile deleted file mode 100644 index 697661a..0000000 --- a/utils/Makefile +++ /dev/null @@ -1,180 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.13 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - - -# A target that is always out of date. -cmake_force: - -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -# The shell in which to execute make rules. -SHELL = /bin/sh - -# The CMake executable. -CMAKE_COMMAND = /usr/local/bin/cmake - -# The command to remove a file. -RM = /usr/local/bin/cmake -E remove -f - -# Escaping for special characters. -EQUALS = = - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/cds-nano-3/edge-ml - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/cds-nano-3/edge-ml - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/local/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache - -.PHONY : rebuild_cache/fast - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." - /usr/local/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache - -.PHONY : edit_cache/fast - -# The main all target -all: cmake_check_build_system - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles /home/cds-nano-3/edge-ml/utils/CMakeFiles/progress.marks - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 utils/all - $(CMAKE_COMMAND) -E cmake_progress_start /home/cds-nano-3/edge-ml/CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 utils/clean -.PHONY : clean - -# The main clean target -clean/fast: clean - -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 utils/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 utils/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -.PHONY : depend - -# Convenience name for target. -utils/CMakeFiles/UtilityLib.dir/rule: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f CMakeFiles/Makefile2 utils/CMakeFiles/UtilityLib.dir/rule -.PHONY : utils/CMakeFiles/UtilityLib.dir/rule - -# Convenience name for target. -UtilityLib: utils/CMakeFiles/UtilityLib.dir/rule - -.PHONY : UtilityLib - -# fast build rule for target. -UtilityLib/fast: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f utils/CMakeFiles/UtilityLib.dir/build.make utils/CMakeFiles/UtilityLib.dir/build -.PHONY : UtilityLib/fast - -motion_detection.o: motion_detection.cpp.o - -.PHONY : motion_detection.o - -# target to build an object file -motion_detection.cpp.o: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f utils/CMakeFiles/UtilityLib.dir/build.make utils/CMakeFiles/UtilityLib.dir/motion_detection.cpp.o -.PHONY : motion_detection.cpp.o - -motion_detection.i: motion_detection.cpp.i - -.PHONY : motion_detection.i - -# target to preprocess a source file -motion_detection.cpp.i: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f utils/CMakeFiles/UtilityLib.dir/build.make utils/CMakeFiles/UtilityLib.dir/motion_detection.cpp.i -.PHONY : motion_detection.cpp.i - -motion_detection.s: motion_detection.cpp.s - -.PHONY : motion_detection.s - -# target to generate assembly for a file -motion_detection.cpp.s: - cd /home/cds-nano-3/edge-ml && $(MAKE) -f utils/CMakeFiles/UtilityLib.dir/build.make utils/CMakeFiles/UtilityLib.dir/motion_detection.cpp.s -.PHONY : motion_detection.cpp.s - -# Help Target -help: - @echo "The following are some of the valid targets for this Makefile:" - @echo "... all (the default if no target is provided)" - @echo "... clean" - @echo "... depend" - @echo "... rebuild_cache" - @echo "... UtilityLib" - @echo "... edit_cache" - @echo "... motion_detection.o" - @echo "... motion_detection.i" - @echo "... motion_detection.s" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /home/cds-nano-3/edge-ml && $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 -.PHONY : cmake_check_build_system -