A Next.js application that uses AI to detect and classify objects in images. Upload an image and get instant results showing what objects are detected and how many of each type.
- AI Object Detection: Powered by Hugging Face's Transformers.js library using the DETR ResNet-50 model
- Real-time Processing: Instant object detection with confidence scoring
- Image Storage: Automatic upload and storage using UploadThing and AWS ECR
- Confidence Filtering: Only displays objects detected with >80% confidence
- Object Counting: Automatically counts multiple instances of the same object
The application follows a containerized architecture deployed on AWS:
- Frontend (Next.js): User interface for image upload and result display
- Web Server: Processes requests and serves TSX files
- AI Model: Xenova/detr-resnet-50 for object detection
- UploadThing: Handles file uploads and temporary storage
- AWS ECR: Stores Docker images
- AWS ECS: Manages and orchestrates containers
- Node.js 18+
- npm or yarn
- UploadThing account and API keys
- AWS account (for deployment)
- Clone the repository:
git clone https://github.com/aleung910/Object_Detect_App.git
cd Object_Detect_App- Install dependencies:
npm install
# or
yarn install- Set up environment variables:
Create a
.env.localfile in the root directory:
UPLOADTHING_SECRET=your_uploadthing_secret
UPLOADTHING_APP_ID=your_app_id- Run the development server:
npm run dev
# or
yarn dev- Open http://localhost:3000 in your browser
- Navigate to the home page
- Click "Upload Object Image" button
- Select an image file (.png or .jpg)
- Click upload and wait for processing
- View detected objects and their counts
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first styling
- Shadcn/ui: Component library
- Transformers.js: Hugging Face library for browser-based ML
- DETR ResNet-50: Object detection model
- Pipeline API: Simplified model inference
- UploadThing: File upload handling
- AWS ECR: Docker image registry
- AWS ECS: Container orchestration
- Docker: Containerization
Object_Detect_App/
├── app/
│ ├── api/
│ │ └── detect-objects/
│ │ └── route.ts # Object detection API endpoint
│ ├── image-classification/
│ │ └── page.tsx # Main upload/detection page
│ ├── styles/
│ │ └── global.css # Global styles
│ └── page.tsx # Home page
├── components/
│ └── ui/ # Reusable UI components
├── utils/
│ └── uploadthing.ts # UploadThing configuration
├── public/
│ ├── diagram.png # Architecture diagram
│ └── paperTexture.jpg # Background texture
└── package.json
Detects objects in an uploaded image.
Request:
- Content-Type:
multipart/form-data - Body: FormData with
filesfield
Response:
{
"url": "https://uploadthing.com/...",
"label": "{\"person\":2,\"chair\":4}"
}Only objects detected with >80% confidence are included in results:
outPut.forEach(({ score, label }: any) => {
if (score > 0.80) {
// Count and display object
}
});Automatically aggregates multiple detections of the same object type:
if (countObj[label]) {
countObj[label]++;
} else {
countObj[label] = 1;
}Build and run the Docker container:
# Build image
docker build -t object-detect-app .
# Run container
docker run -p 3000:3000 object-detect-app- Push Docker image to ECR
- Create ECS task definition
- Deploy to ECS cluster
- Configure load balancer and domain
This project is open source and available under the MIT License.
- Hugging Face for Transformers.js
- UploadThing for file upload handling
- Xenova for the DETR ResNet-50 model
- Shadcn for UI components
