├── usps_classes.txt ├── images ├── usps.jpg ├── deepstack-log.jpg └── usps_detected.jpg ├── detect.py └── README.md /usps_classes.txt: -------------------------------------------------------------------------------- 1 | USPS -------------------------------------------------------------------------------- /images/usps.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sstratoti/DeepStack_USPS/HEAD/images/usps.jpg -------------------------------------------------------------------------------- /images/deepstack-log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sstratoti/DeepStack_USPS/HEAD/images/deepstack-log.jpg -------------------------------------------------------------------------------- /images/usps_detected.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sstratoti/DeepStack_USPS/HEAD/images/usps_detected.jpg -------------------------------------------------------------------------------- /detect.py: -------------------------------------------------------------------------------- 1 | from deepstack_sdk import Detection,ServerConfig 2 | import os 3 | 4 | config = ServerConfig("http://localhost:80") 5 | detector = Detection(config=config, name="USPS") 6 | 7 | detections = detector.detectObject(image=os.path.join("images", "usps.jpg"), output=os.path.join("images", "usps_new.jpg")) 8 | 9 | for detection in detections: 10 | print("Name: {}".format(detection.label)) 11 | print("Confidence: {}".format(detection.confidence)) 12 | print("x_min: {}".format(detection.x_min)) 13 | print("x_max: {}".format(detection.x_max)) 14 | print("y_min: {}".format(detection.y_min)) 15 | print("y_max: {}".format(detection.y_max)) 16 | print("-----------------------") 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DeepStack_USPS 2 | 3 | ![](images/usps_detected.jpg) 4 | 5 | This repository provides a custom DeepStack model that has been trained detecting ONLY the **USPS logo**. This was created after I discovered that the Deepstack OpenLogo custom model I was using did not contain USPS. The owner of that repo suggested that we create our own, so I decided to give it a shot! 6 | 7 | In my use case, I have a Blue Iris clone of my main house cameras that is setup to NOT record. It's only set up to alert if it sees a car, truck, van or bus. The alert image is then sent over MQTT to node-red. It's then read in, and thrown against OpenLogo to see if it matches fedex, ups, amazon or dhl. If nothing is reported back, then I'll throw it against this USPS custom object end point. Essentially it's scanning each alert image multiple times, but its quick enough in processing that it should alert me when it sees the logo. 8 | 9 | The main goal? My wife mails back her empty soda stream cannisters and then new ones are sent to us. Instead of having to head to a post office, its easier for us to catch our mail carrier and hand them the package when they're outside. Happy wife... 10 | 11 | - **Create API and Detect Logos** 12 | - **Discover more Custom Models** 13 | - **Train your own Model** 14 | 15 | 16 | 17 | # Create API and Detect Logos 18 | 19 | The only logo in the model is "USPS". So this is a unique custom object endpoint that is only used for USPS detection. The way I understand it (which honestly, I just followed the directions), the AI training is based off of the images provided and the portion of the images that I tag with class names. So I could have done "truck" or "van" or "trailer" along with the USPS logo, but I wanted to keep things simple. 20 | 21 | To start detecting, follow the steps below 22 | 23 | - **Install DeepStack:** Install DeepStack AI Server with instructions on DeepStack's documentation via [https://docs.deepstack.cc](https://docs.deepstack.cc/index.html#installation) 24 | - **Download Custom Model:** Download the trained custom model `USPS.pt` via [this link](https://github.com/sstratoti/DeepStack_USPS/releases/download/v1/USPS.pt). Create a folder on your machine and move the model to this folder. 25 | 26 | E.g A path on Windows Machine `C\Users\MyUser\Documents\DeepStack-Models`, which will make your model file path `C\Users\MyUser\Documents\DeepStack-Models\USPS.pt` 27 | 28 | - **Run DeepStack:** To run DeepStack AI Server with the custom USPS model, run the command that applies to your machine as detailed on DeepStack's documentation [linked here](https://docs.deepstack.cc/custom-models/deployment/index.html#starting-deepstack). 29 | 30 | E.g 31 | 32 | For a Windows version, you run the command below 33 | ```bash 34 | deepstack --MODELSTORE-DETECTION "C\Users\MyUser\Documents\DeepStack-Models" --PORT 80 35 | ``` 36 | 37 | For a Linux machine 38 | ```bash 39 | sudo docker run -v /home/MyUser/Documents/DeepStack-Models -p 80:5000 deepquestai/deepstack 40 | ``` 41 | Once DeepStack runs, you will see a log like the one below in your `Terminal/Console` 42 | 43 | ![](images/deepstack-log.jpg) 44 | 45 | That means DeepStack is running your custom `USPS` model and now ready to start detecting logos in images via the API enpoint `http://localhost:80/v1/vision/custom/USPS` or `http://your_machine_ip:80/v1/vision/custom/USPS` 46 | 47 | - **Detect Logo in image:** You can detect logos in an image by sending a `POST` request to the url mentioned above with the paramater `image` set to an `image` using any proggramming language or with a tool like POSTMAN. For the purpose of this repository, we have provided a sample Python code below. 48 | 49 | - A sample image can be found in `images/usps.jpg` of this repository 50 | 51 | 52 | ![](images/fedex.jpg) 53 | 54 | - Install Python and install the **DeepStack Python SDK** via the command below 55 | ```bash 56 | pip install deepstack_sdk 57 | ``` 58 | - Run the Python file `detect.py` in this repository. 59 | 60 | ```bash 61 | python detect.py 62 | ``` 63 | - After the code runs, you will find a new image in `images/usps_new.jpg` with the detection visualized, with the following results printed in the Terminal/Console. 64 | 65 | ``` 66 | Name: USPS 67 | Confidence: 0.93151146 68 | x_min: 74 69 | x_max: 102 70 | y_min: 189 71 | y_max: 210 72 | ----------------------- 73 | Name: USPS 74 | Confidence: 0.9639365 75 | x_min: 181 76 | x_max: 288 77 | y_min: 172 78 | y_max: 246 79 | ----------------------- 80 | Name: USPS 81 | Confidence: 0.9687089 82 | x_min: 356 83 | x_max: 408 84 | y_min: 176 85 | y_max: 221 86 | ----------------------- 87 | ``` 88 | 89 | ![](images/usps_detected.jpg) 90 | 91 | 92 | 93 | # Discover more Custom Models 94 | 95 | Please visit the OpenLogo repository that started this whole thing. Almost all of this readme and code was copied from there. [https://github.com/OlafenwaMoses/DeepStack_OpenLogo](https://github.com/OlafenwaMoses/DeepStack_OpenLogo) . 96 | 97 | For more custom DeepStack models that has been trained and ready to use, visit the Custom Models sample page on DeepStack's documentation [https://docs.deepstack.cc/custom-models-samples/](https://docs.deepstack.cc/custom-models-samples/) . 98 | 99 | # Train your own Model 100 | 101 | If you will like to train a custom model yourself (this is what I did!), follow the instructions below. 102 | 103 | - **Prepare and Annotate:** Collect images on and annotate object(s) you plan to detect as [ detailed here ](https://docs.deepstack.cc/custom-models/datasetprep/index.html) 104 | - **Train your Model:** Train the model as [detailed here](https://docs.deepstack.cc/custom-models/training/index.html) --------------------------------------------------------------------------------