A Node.js script and web demo that uses TensorFlow.js and the COCO-SSD model to detect chickens (birds) in images.
- π Detects chickens/birds in images using machine learning
- π Shows confidence scores and bounding box coordinates
- π Supports single images or batch processing of directories (Node.js)
- πΌοΈ Works with JPEG, PNG, BMP, and GIF formats
- π Uses TensorFlow.js for fast, client-side inference
- π Includes both command-line tool and web interface
- Clone or download this project
- Install dependencies:
npm install
node chicken-count.js path/to/your/image.jpgnode chicken-count.js path/to/image/directory# Local model files
node chicken-count-teachable.js ./image.jpg ./model/model.json
# Remote Teachable Machine model
node chicken-count-teachable.js ./image.jpg https://teachablemachine.withgoogle.com/models/YOUR_ID/model.jsonnode chicken-count-teachable.js ./image-directory/ ./model/model.json- Open
web-demo.htmlin your web browser - Drag and drop an image or click to select one
- Click "Detect Chickens" to analyze the image
- View results with bounding boxes drawn on detected chickens
Loading COCO-SSD model...
This may take a moment on first run as the model is downloaded...
Model loaded successfully!
Analyzing image: chicken-photo.jpg
=== DETECTION RESULTS ===
Image: chicken-photo.jpg
Image size: 800x600
Total objects detected: 3
Birds/Chickens detected: 2
Bird/Chicken detections:
1. Confidence: 87.3%
Location: x=120, y=200
Size: 180x240
2. Confidence: 76.5%
Location: x=450, y=180
Size: 150x200
All detected objects:
1. bird (87.3%)
2. bird (76.5%)
3. person (65.2%)
========================
π Found 2 chicken(s) in the image!
Loading custom Teachable Machine model...
Model URL: https://teachablemachine.withgoogle.com/models/YOUR_ID/model.json
Custom model loaded successfully!
Model input shape: [,224,224,3]
Model output shape: [,2]
Analyzing image: chicken-photo.jpg
=== TEACHABLE MACHINE RESULTS ===
Image: chicken-photo.jpg
Original image size: 800x600
All predictions:
No Chicken: 15.2%
Chicken: 84.8%
Best prediction: Chicken (84.8%)
π CHICKEN DETECTED! Confidence: 84.8%
================================
π Teachable Machine detected a chicken with 84.8% confidence!
The script offers two different approaches:
- TensorFlow.js: Machine learning framework for JavaScript
- COCO-SSD Model: Pre-trained object detection model that can identify 80 different objects
- Jimp: Image processing library for Node.js (command-line version)
- Browser APIs: Canvas and Image APIs for the web demo
The COCO-SSD model classifies chickens under the "bird" category, so the script filters for bird detections with confidence scores above 50%.
- Custom Training: Train your own model specifically for chickens at https://teachablemachine.withgoogle.com/
- Higher Accuracy: Specialized for your specific use case
- Flexible Classes: Can distinguish between different chicken breeds or other custom categories
- Smaller Size: Usually 1-5MB vs 10MB for COCO-SSD
- Go to Teachable Machine: Visit https://teachablemachine.withgoogle.com/
- Select Image Project: Choose "Image Project"
- Add Classes: Create classes like "Chicken", "No Chicken", or specific breeds
- Upload Images: Add 10+ images per class for better accuracy
- Train: Click "Train Model" and wait for completion
- Export: Choose "TensorFlow.js" and copy the model URL
- Use: Run
node chicken-count-teachable.js image.jpg YOUR_MODEL_URL
chicken-count.js- Main Node.js script for command-line usage (uses COCO-SSD model)chicken-count-teachable.js- Version for custom Teachable Machine modelsweb-demo.html- Interactive web interface for browser-based detectiontest-installation.js- Test script to verify installationpackage.json- Node.js dependencies and scriptsREADME.md- This documentation file
To verify everything is working correctly:
node test-installation.jsThis will load the model and confirm all dependencies are properly installed.
- The model detects "birds" in general, not specifically chickens
- Accuracy depends on image quality, lighting conditions, and chicken visibility
- Small or partially obscured chickens may not be detected
- False positives may occur with other bird-like objects or bird-shaped decorations
- Accuracy depends on the quality and quantity of training images
- Requires at least 10+ images per class for good results
- May not generalize well to very different environments than training data
- Custom models need to be retrained if requirements change
- The first run may take longer as the model needs to be downloaded (~10MB for COCO-SSD, 1-5MB for Teachable Machine)
- Internet connection required for initial model download
- Node.js 14+ (for command-line version)
- Modern web browser with JavaScript enabled (for web demo)
- Internet connection for initial model download
@tensorflow/tfjs: TensorFlow.js core library@tensorflow-models/coco-ssd: Pre-trained COCO-SSD object detection modeljimp: Image processing for Node.jsjsdom: DOM environment simulation for Node.js
- Ensure you have a stable internet connection
- The model download is ~10MB and may take time on slower connections
- Clear your browser cache if using the web demo
- Verify image format is supported (JPEG, PNG, BMP, GIF)
- Check that image file exists and is readable
- Large images may take longer to process
- For better performance, use smaller images (under 1MB)
- The web demo runs entirely in your browser - no data is sent to servers
- First detection may be slower due to model initialization
MIT License - Feel free to use and modify as needed!
Feel free to submit issues and enhancement requests!