Skip to content

olafrv/pycatdetector

Repository files navigation

About PyCatDetector

Screener (Live View) Discord Notification (WebHook)

Python Cat Detector (GitHub license) is a tool to detect the presence of my cat "Cookie" near her litterbox and alerts me to clean it.

Basically, the application grabs video frames from an IP camera RTSP stream, uses a neural network to identify a cat object, and play a message in a speaker.

All hardware and software used by pycatdetector (i.e. Camera, Linux Server and Speaker) can reach each other via my local WiFi network.

Architecture & Workflow

The software architecture is pretty simple as follows:

sequenceDiagram
    participant Camera
    participant Recorder
    participant Detector
    participant Encoder
    participant Screener
    participant Notifier
    participant Channel
    loop Read (RSTP)
      Camera->>Recorder: Image
    end
    loop Read (Queue)
      Recorder->>Detector: Image
    end
    loop Read (Queue)
      Detector->>Screener: Image
    end
    Detector->>Encoder: write(Video, Image)
    loop Read (Queue)
      Detector->>Notifier: Label/Score
    end
    Notifier->>Channel: notify(Label)
Loading

Requirements

General

This Python package has been tested and designed for:

AVX Instruction Set

NOTICE: If your Linux is a Virtual Machine running on a Windows host you
need to disable Windows Security > Core Isolation > Memory Protection.

Linux (or WSL2)

Check if your CPU (or vCPU) is supporting the AVX instruction set:

cat /proc/cpuinfo | grep -i avx

PyTorch

Run the following to check if AVX is enabled: test_aaa_torch.py.

See more information on:
https://pytorch.org/get-started/locally/#windows-verification

Usage

Configuration

sudo apt install make
git clone "https://github.com/olafrv/pycatdetector.git"
cd pycatdetector
mv config.example.yaml config.yaml # edit manually afterwards

Run (Python)

make install         # install end user requirements
make check-config    # checks for YAML parsing errors
make run             # with python3 interpreter

Run (Docker)

# If you don't have it (latest docker official version)
# https://github.com/docker/docker-install
curl -fsSL https://get.docker.com -o get-docker.sh; sh get-docker.sh
make docker.build    # build docker image with python requirements
make docker.run      # A) without compose, and removed after stopped
make docker.start    # B.1) with compose running in background as service
make docker.stop     # B.2) stop the composed container service
make docker.restart  # B.3) restart the composed container service
make docker.sh       # open bash in the container service
make docker.clean    # delete local docker images to save space

Uninstall

make uninstall       # remove python requirements and disposable folders

Advanced/Developement

# Metadata and Requirements
make metadata             # show release METADATA file content
make install.dev          # install development requirements
make package.outdated     # check outdated python packages
# Binary build with Nuitka3
make build                # build binary with nuitka3
make clean                # delete local disposable files
make run.bin              # run ./dist/main.bin dynamically linked binary
# Profiling and Testing
make profile              # run python3 profiling over main.py
make profile.view         # check profiling results with snake
make test                 # run ./pycatdetector/tests/*
make test.coverage        # check call coverage during runtime
make test.coverage.report # check test coverage after runtime
# GitHub Release
# See Makefile for required GITHUB_* required variables
# Adjust METADATA file before running the following commands
# make github.* perform code formatting, build, test, push and release
make github.release       # create a new github package release

References

OpenCV - a.k.a. cv2

PyTorch & Torchvision

GluonCV (Deprecated since v1.2.0)

Apache MXNet (Deprecated since v1.2.0)

PIL

Deep Learning

PEP 8 – Style Guide for Python Code

PEP 0 – Index of Python Enhancement Proposals (PEPs)

About

A tool for detect and alert the presence of my cat using a neural network

Topics

Resources

License

Stars

Watchers

Forks

Packages