|
| 1 | +# Dairy Product Detection Pipeline |
| 2 | + |
| 3 | +This pipeline detects and extracts dairy product packets from a folder of image |
| 4 | +frames. |
| 5 | + |
| 6 | +### Prerequisites |
| 7 | + |
| 8 | +- GCP account with Compute Engine access |
| 9 | +- A folder containing image frames to process |
| 10 | + |
| 11 | +### Setup Instructions |
| 12 | + |
| 13 | +### 1. Create a VM Instance |
| 14 | + |
| 15 | +### 2. Download the Setup Script |
| 16 | + |
| 17 | +SSH into your VM instance and run: |
| 18 | + |
| 19 | +```bash |
| 20 | +curl -o setup.sh https://raw.githubusercontent.com/tensorflow/models/master/official/projects/waste_identification_ml/llm_applications/milk_pouch_detection/setup.sh |
| 21 | +``` |
| 22 | + |
| 23 | +### 3. Run the Setup Script |
| 24 | + |
| 25 | +Execute the setup script to download all required files and dependencies: |
| 26 | + |
| 27 | +```bash |
| 28 | +bash setup.sh |
| 29 | +``` |
| 30 | + |
| 31 | +This will automatically download all necessary files for running the |
| 32 | +detection pipeline. |
| 33 | + |
| 34 | +### 4. Process Your Images |
| 35 | + |
| 36 | +Given a folder path containing your test images, run: |
| 37 | + |
| 38 | +```bash |
| 39 | +bash run_pipeline.sh --input_dir=/path/to/test_images |
| 40 | +``` |
| 41 | + |
| 42 | +Replace `/path/to/test_images` with the actual path to your image folder. |
| 43 | + |
| 44 | +### 5. View Results |
| 45 | + |
| 46 | +The pipeline will create two folders inside your input directory: |
| 47 | + |
| 48 | +- **`dairy/`** - Contains all cropped objects identified as dairy products |
| 49 | +- **`others/`** - Contains all cropped objects that are not dairy products |
| 50 | + |
| 51 | +### Example |
| 52 | + |
| 53 | +```bash |
| 54 | +# If your images are in /home/user/test_images |
| 55 | +bash run_pipeline.sh --input_dir=/home/user/test_images |
| 56 | + |
| 57 | +# Results will be in: |
| 58 | +# /home/user/test_images/dairy/ |
| 59 | +# /home/user/test_images/others/ |
| 60 | +``` |
| 61 | + |
| 62 | +### Troubleshooting |
| 63 | + |
| 64 | +- Ensure your VM has sufficient memory and disk space |
| 65 | +- Verify that all image files are in supported formats (JPG, PNG, etc.) |
| 66 | +- Check that you have proper read/write permissions for the input directory |
| 67 | + |
| 68 | +## Dataset Creation for Training ML Models |
| 69 | + |
| 70 | +This guide explains how to create datasets for training image classifier, object |
| 71 | +detection, or instance segmentation models from images of a particular |
| 72 | +category. |
| 73 | + |
| 74 | +### 1. Prepare Your Images |
| 75 | + |
| 76 | +Organize your images into a folder. These should be images containing objects of |
| 77 | +a particular category (e.g., dairy products, bottles, cans, etc.). |
| 78 | + |
| 79 | +### 2. Run the Extract Objects Script |
| 80 | + |
| 81 | +Execute the following command to extract objects and generate dataset files: |
| 82 | + |
| 83 | +```python |
| 84 | +python3 extract_objects.py --input_dir=/test_images --category_name=dairy |
| 85 | +``` |
| 86 | + |
| 87 | +Replace: |
| 88 | + |
| 89 | +- `/test_images` with the path to your image folder. |
| 90 | +- `dairy` with your category name (e.g., bottles, cans, plastic, etc.) |
| 91 | + |
| 92 | +### 3. Generated Outputs |
| 93 | + |
| 94 | +The script will generate two types of outputs inside your input directory: |
| 95 | + |
| 96 | +#### For Image Classification Models |
| 97 | + |
| 98 | +A folder named **`tempdir/`** will be created containing: |
| 99 | + |
| 100 | +- All cropped objects extracted from the images |
| 101 | +- These cropped images can be directly used to train an image classifier model |
| 102 | + |
| 103 | +#### For Object Detection/Segmentation Models |
| 104 | + |
| 105 | +A COCO format JSON file will be generated containing: |
| 106 | + |
| 107 | +- Annotations for all detected objects |
| 108 | +- Bounding boxes and segmentation masks |
| 109 | +- This file can be used to train object detection or instance segmentation models |
| 110 | + |
| 111 | +### Example Usage |
| 112 | + |
| 113 | +```python |
| 114 | +# Extract dairy products from images |
| 115 | +python3 extract_objects.py --input_dir=/home/user/dairy_images --category_name=dairy |
| 116 | + |
| 117 | +# Extract plastic bottles |
| 118 | +python3 extract_objects.py --input_dir=/home/user/bottle_images --category_name=bottles |
| 119 | + |
| 120 | +# Extract metal cans |
| 121 | +python3 extract_objects.py --input_dir=/home/user/can_images --category_name=cans |
| 122 | +``` |
| 123 | + |
| 124 | +### Output Structure |
| 125 | + |
| 126 | +After running the script, your directory will look like: |
| 127 | + |
| 128 | +``` |
| 129 | +/test_images/ |
| 130 | +├── image1.jpg |
| 131 | +├── image2.jpg |
| 132 | +├── tempdir/ # Cropped objects for classification |
| 133 | +│ ├── crop_001.jpg |
| 134 | +│ ├── crop_002.jpg |
| 135 | +│ └── ... |
| 136 | +└── annotations.json # COCO format file for detection/segmentation |
| 137 | +``` |
| 138 | + |
| 139 | +### Use Cases |
| 140 | + |
| 141 | +- **Image Classification**: Use images from `tempdir/` folder |
| 142 | +- **Object Detection**: Use the COCO JSON file with original images |
| 143 | +- **Instance Segmentation**: Use the COCO JSON file with segmentation masks |
| 144 | + |
| 145 | +### Tips |
| 146 | + |
| 147 | +- Ensure your images are clear and objects are visible |
| 148 | +- Use consistent naming for category names across your datasets |
| 149 | +- Verify the generated annotations before training your models |
0 commit comments