{"id":13644470,"url":"https://github.com/heathhenley/RhodyCarCounter","last_synced_at":"2025-04-21T10:33:28.941Z","repository":{"id":65828714,"uuid":"585720949","full_name":"heathhenley/RhodyCarCounter","owner":"heathhenley","description":"An app that uses Yolo to count the cars passing by traffic cams mostly in the Providence, RI area.","archived":false,"fork":false,"pushed_at":"2024-04-06T15:00:20.000Z","size":14790,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-09T17:41:52.159Z","etag":null,"topics":["deep-learning","fastapi","image-processing","object-detection","traffic","yolov8"],"latest_commit_sha":null,"homepage":"https://heathhenley.github.io/RhodyCarCounter/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heathhenley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-01-05T22:37:04.000Z","updated_at":"2024-03-21T03:09:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"75658ee0-1678-4e67-a15f-a9e3cfcf6f7b","html_url":"https://github.com/heathhenley/RhodyCarCounter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heathhenley%2FRhodyCarCounter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heathhenley%2FRhodyCarCounter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heathhenley%2FRhodyCarCounter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heathhenley%2FRhodyCarCounter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heathhenley","download_url":"https://codeload.github.com/heathhenley/RhodyCarCounter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250040460,"owners_count":21365109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","fastapi","image-processing","object-detection","traffic","yolov8"],"created_at":"2024-08-02T01:02:05.531Z","updated_at":"2025-04-21T10:33:24.432Z","avatar_url":"https://github.com/heathhenley.png","language":"Python","funding_links":[],"categories":["Object Detection Applications"],"sub_categories":[],"readme":"# RhodyCarCounter\nUse Yolo to count the cars passing by traffic cams mostly in the Providence, RI area. \n\n## Overall Current Architecture\n![Current Architecture](/docs/img/traffic_app_setup.png \"Current Architecture\")\n\n## Backend\n### Data and API\nUses Postgres database to store the data, and `FastAPI` with `sqlalchemy` to serve the data up for a public API. The API can be tested ([here](https://rhodycarcounter-production.up.railway.app/api/cameras) and [docs](https://rhodycarcounter-production.up.railway.app/docs/)).\n\n### Car Detection Model\nOriginally created to play around with the Yolo model implementation introduced\nthrough a programming assignment in the deeplearning.ai [Deep Learning courses](https://www.deeplearning.ai/courses/deep-learning-specialization/) on Coursera. Uses the YOLOv8 pretrained model from [ultralytics](https://docs.ultralytics.com/). I then trained it a little bit on some of the traffic cam data that is publically available and was used for this [paper](https://proceedings.neurips.cc/paper/2019/file/ee389847678a3a9d1ce9e4ca69200d06-Paper.pdf). But we have a lot of room to improve. It pulls all the camera images directly from the [RIDOT](https://www.dot.ri.gov/travel/index.php) traffic site.\n\n#### Most Recent Images\nThe worker sticks the cameras and the results of the car counting into the\ndatabase, and uploads the latest labelled image from a camera to s3.\n\nFor example, here's the most recently processed snapshot from the traffic camera at the Rt 6/10 interchange across from the Providence Place mall.\n\n![Most recent RT 6/10 camera with labels](https://rhodycarcounter.s3.amazonaws.com/6_10+interchange.jpg?)\n\nThe worker runs through all the cameras every 5 minutes, but that might be adjusted after looking at the data more. And after determining how much data I can store for free-ish 🤣.\n\n### Model Improvement\nI am planning to start to collect a small sample of images and label them\nmyself, especially some examples where the model preformed poorly, and retrain\njust the last layer on the new data. It will also help to remove the classes\nand only detect vehicles.\n\n### Backend Directory Structure\nThe directories contain different parts of the project:\n- `worker` - this is meant to run as a 'service', just loop for ever,\npull down images from the traffic cams, run YOLO on them, and drop the results into a postgres database.\n- `api` - contains the `FastAPI` app that connects to the database and exposes the path operations to get to the data (GET only).\n\nBoth of these use the `database` module to connect to the database. It's\nliterally just duplicated in both places (I know...it was a hack to get railway to work).\nI'm going to make it a submodule.\n\n## Frontend\nIt's a work in progress (https://heathhenley.github.io/RhodyCarCounter/)\n\nUsing react, react-bootstrap, and react-leaftlet to create a map of the cameras\nand the counts and show a table of all the available cameras. Uses recharts to\nplot the latests data.\n\n## How to run locally\n### The whole system\nI just added a docker-compose file to run the backend and the frontend locally. You can run it with: `docker compose up` and it will spin up the API server on \nhttp://localhost:5001, a postgres database on port 5432, and the frontend on http://localhost:3000/RhodyCarCounter. It also copies the cameras from the the camera table in the \"production\" database. \n\nThe last thing to do is to point the front end to the API running on your local machine at http://localhost:5001/api. It should be simple to set up, but I haven't set it up yet. So right now even if you run the frontend locally,, it will still pull data from the production API.\n\n### Individual parts\nIf you only want to run the frontend:\n\n- clone repo\n- navigate to the frontend/traffic_count directory\n- run npm install - to install the dependencies\n- run npm start - the start the dev server on localhost\n\nRunning the backend will require a little more work. \n\nIn general the idea is:\n- set the environment variables that are in this template: https://github.com/heathhenley/RhodyCarCounter/blob/main/backend/env-template.bat (you don't actually need the AWS ones unless you want to stick the images in an AWS bucket) --\u003e the backend needs a database, I'm running postgres on railway.app, you could install locally or even use sqlite. The DB_CONNECT_STR for sqlite should be something like \"file:./db.sqlite\" which is simpler than postgres.\n- clone the repo and navigate to backend/api\nto run the api: (you need python 3.10 or higher)\n- create a venv to install the api dependencies python -m venv api_env and activate it (run Scripts/activate)\n- install the api dependencies with python -m pip install -r requirements-api.txt\n- run the api with uvicorn api:app --reload\nit uses FastAPI, and their docs are awesome (https://fastapi.tiangolo.com/)\n\nIf you want to run the worker, I would create a separate virtual environment:\n- create a venv to install the api dependencies python -m venv worker_env and activate it (run Scripts/activate)\n- install the worker dependencies with python -m pip install -r requirements-worker.txt\n- run the worker with python worker/traffic.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheathhenley%2FRhodyCarCounter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheathhenley%2FRhodyCarCounter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheathhenley%2FRhodyCarCounter/lists"}