Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/traditional/features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,55 @@ The raw image files are not committed to Git.

## Validation

| Feature | Shape | Data type |
| --- | --- | --- |
| Feature | Shape | Data type | Output length |
| --- | --- | --- | --- |
| HOG | `(6084,)` | `float32` | Fixed |
| RGB colour histogram | `(96,)` | `float32` | Fixed |
| Combined HOG and colour | `(6180,)` | `float32` | Fixed |
| SIFT descriptors | `(N, 128)` | `float32` | Variable |

Both methods were tested on images from different classes and produced fixed-length feature vectors.
The HOG, colour, and combined features produced fixed-length vectors. SIFT produced a variable number of 128-dimensional descriptors.

## Current Branch
## Downloading Traditional Feature Files

Current branch:
The extracted traditional feature files are stored separately on OneDrive because the `outputs` folder is not tracked by Git.

`Chaohao_TraditionalFeature3`
Download the feature files from:

This branch continues the pipeline by combining the HOG and colour features.
[Traditional feature files on OneDrive](https://unsw-my.sharepoint.com/:f:/g/personal/z5528581_ad_unsw_edu_au/IgAsAxZV1fJQSbL1AAmSgGoaAU-ZRhVTJmVLsHFxH7leipA)

After downloading, place the files in:

```text
outputs/traditional_features/
```

The expected files are:

```text
train_combined_features.npz
validation_combined_features.npz
test_combined_features.npz
```

Each `.npz` file contains:

```text
features
labels
file_paths
```

These files are generated by `features.ipynb` and can be loaded by `cache.ipynb` or `traditional_classifier.ipynb`.

The expected folder structure is:

```text
HOG: 6084
Colour: 96
Combined: 6180
outputs/
└── traditional_features/
├── train_combined_features.npz
├── validation_combined_features.npz
└── test_combined_features.npz
```

## Maintenance
Expand All @@ -270,6 +298,6 @@ When adding a new feature:

- use the shared settings from `config.py`
- accept a PIL image as input
- return a one-dimensional `float32` NumPy array
- keep the output length fixed
- return `float32` NumPy arrays
- clearly state whether the output is fixed-length or variable-length
- test the method on images from different classes
83 changes: 5 additions & 78 deletions src/traditional/features/cache.ipynb

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions src/traditional/features/color.ipynb
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "2698ae8b",
"metadata": {},
"source": [
"Extract an RGB colour histogram from each image.\n",
"\n",
"The red, green, and blue channel histograms are normalised and combined into one fixed-length feature vector."
]
},
{
"cell_type": "markdown",
"id": "7b1019cf",
"metadata": {},
"source": [
"# Colour Histogram Feature Extraction\n",
"\n",
"It extracts colour histogram features from the iNaturalist images."
"Extract colour histogram features from the iNaturalist images."
]
},
{
Expand Down
42 changes: 19 additions & 23 deletions src/traditional/features/combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"id": "d79d4428",
"metadata": {},
"source": [
"## 1.Import libraries"
"## 1. Import libraries"
]
},
{
Expand All @@ -44,9 +44,9 @@
"id": "fb4d7786",
"metadata": {},
"source": [
"## 2.Load the shared project configuration\n",
"## 2. Load the shared project configuration\n",
"\n",
"It finds the project root and imports `config.py`.\n",
"Find the project root and imports `config.py`.\n",
"\n",
"Using the shared configuration avoids personal absolute paths and keeps the notebook working on different computers."
]
Expand Down Expand Up @@ -94,9 +94,9 @@
"id": "ed08813c",
"metadata": {},
"source": [
"## 3.Load and check a sample image\n",
"## 3. Load and check a sample image\n",
"\n",
"It selects a sample image from the training set, checks that the file exists, loads it as an RGB image, and displays its basic information.\n",
"Select a sample image from the training set, checks that the file exists, loads it as an RGB image, and displays its basic information.\n",
"\n",
"Change `sample_index` to test another image."
]
Expand Down Expand Up @@ -188,11 +188,11 @@
"id": "5ccbc08f",
"metadata": {},
"source": [
"## 4.Define the HOG feature function\n",
"## 4. Define the HOG feature function\n",
"\n",
"This function uses the same HOG settings as `hog.ipynb`.\n",
"Use the same HOG settings as `hog.ipynb`.\n",
"\n",
"It resizes the image, converts it to grayscale, and returns a fixed-length `float32` feature vector."
"Resize the image, converts it to grayscale, and returns a fixed-length `float32` feature vector."
]
},
{
Expand Down Expand Up @@ -224,11 +224,11 @@
"id": "103c08d1",
"metadata": {},
"source": [
"## 5.Define the colour histogram function\n",
"## 5. Define the colour histogram function\n",
"\n",
"This function uses the same RGB histogram method as `color.ipynb`.\n",
"Use the same RGB histogram method as `color.ipynb`.\n",
"\n",
"It resizes the image, calculates a 32-bin histogram for each RGB channel, normalises each histogram, and combines them into one `float32` feature vector."
"Resize the image, calculates a 32-bin histogram for each RGB channel, normalises each histogram, and combines them into one `float32` feature vector."
]
},
{
Expand Down Expand Up @@ -268,9 +268,9 @@
"id": "7ab0b3dd",
"metadata": {},
"source": [
"## 6.Define the combined feature function\n",
"## 6. Define the combined feature function\n",
"\n",
"This function extracts the HOG feature and RGB colour histogram from the same image.\n",
"Extract the HOG feature and RGB colour histogram from the same image.\n",
"\n",
"The two feature vectors are then joined into one fixed-length `float32` vector."
]
Expand Down Expand Up @@ -298,11 +298,9 @@
"id": "a52de3be",
"metadata": {},
"source": [
"## 7.Test the combined feature\n",
"## 7. Test the combined feature\n",
"\n",
"It extracts the HOG, colour, and combined features from the sample image.\n",
"\n",
"It checks the output shape, data type, and whether the combined feature contains invalid values."
"Extract the three feature vectors from one sample image and check the final output."
]
},
{
Expand Down Expand Up @@ -342,11 +340,9 @@
"id": "980f7173",
"metadata": {},
"source": [
"## 8.Check the combined feature sections\n",
"\n",
"It checks that the combined feature keeps the correct order.\n",
"## 8. Check the feature order\n",
"\n",
"The first part should match the HOG feature, and the remaining part should match the colour feature."
"Check that the HOG values come first and the colour values come after them."
]
},
{
Expand Down Expand Up @@ -391,7 +387,7 @@
"id": "951a4f93",
"metadata": {},
"source": [
"## 9.Test images from different classes\n",
"## 9. Test images from different classes\n",
"\n",
"It selects sample images from different labels and checks whether the combined feature has the same shape and data type for every image."
]
Expand Down Expand Up @@ -458,7 +454,7 @@
"id": "96d2157d",
"metadata": {},
"source": [
"## 10.Final validation\n",
"## 10. Final validation\n",
"\n",
"It performs a final check of the combined feature before it is used in the feature caching pipeline."
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,9 @@
"id": "92d4e928",
"metadata": {},
"source": [
"## 21. Final validation\n",
"## 21. Final check\n",
"\n",
"Perform the final checks on all extracted feature matrices and saved output files."
"Check the final feature files before using them for classifier training."
]
},
{
Expand Down
36 changes: 15 additions & 21 deletions src/traditional/features/sift.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"source": [
"## 3. Load and check a sample image\n",
"\n",
"It selects one image from the training set, checks the image path, and displays its basic information."
"Select one image from the training set, check the image path, and display its basic information."
]
},
{
Expand Down Expand Up @@ -186,7 +186,7 @@
"source": [
"## 4. Define the SIFT feature function\n",
"\n",
"It resizes the image, converts it to grayscale, and extracts SIFT keypoints and descriptors.\n",
"Resizes the image, converts it to grayscale, and extracts SIFT keypoints and descriptors.\n",
"\n",
"`max_features=500` requests approximately 500 of the strongest keypoints.\n",
"\n",
Expand Down Expand Up @@ -251,7 +251,7 @@
"source": [
"## 5. Test the SIFT feature\n",
"\n",
"This cell extracts SIFT keypoints and descriptors from the sample image and checks the output."
"Extract SIFT keypoints and descriptors from the sample image and check the output."
]
},
{
Expand Down Expand Up @@ -292,7 +292,7 @@
"source": [
"## 6. Visualise the SIFT keypoints\n",
"\n",
"It draws the detected SIFT keypoints on the resized sample image."
"Draw the detected SIFT keypoints on the resized sample image."
]
},
{
Expand Down Expand Up @@ -342,7 +342,7 @@
"source": [
"## 7. Check the descriptor values\n",
"\n",
"It checks the value range and basic statistics of the SIFT descriptors."
"Check the value range and basic statistics of the SIFT descriptors."
]
},
{
Expand Down Expand Up @@ -381,7 +381,7 @@
"source": [
"## 8. Visualise one SIFT descriptor\n",
"\n",
"It displays the 128 values of the first SIFT descriptor.\n",
"Display the 128 values of the first SIFT descriptor.\n",
"\n",
"Each descriptor describes the local gradient information around one detected keypoint."
]
Expand Down Expand Up @@ -423,7 +423,7 @@
"source": [
"## 9. Test images from different classes\n",
"\n",
"This cell tests the SIFT feature extractor on images from different labels.\n",
"Test the SIFT feature extractor on images from different labels.\n",
"\n",
"The number of descriptors may change between images, but every descriptor must contain 128 values."
]
Expand Down Expand Up @@ -513,7 +513,7 @@
"source": [
"## 10. Display the test results\n",
"\n",
"This cell places the SIFT test results into a table for easier comparison."
"It places the SIFT test results into a table for easier comparison."
]
},
{
Expand Down Expand Up @@ -628,7 +628,7 @@
"id": "e587cb77",
"metadata": {},
"source": [
"## 11.Visualise keypoints from different classes\n",
"## 11. Visualise keypoints from different classes\n",
"\n",
"Display the detected SIFT keypoints for the selected images from different classes."
]
Expand Down Expand Up @@ -746,7 +746,7 @@
"source": [
"## 12. Check the descriptor dimensions\n",
"\n",
"It confirms that all tested SIFT descriptors contain 128 values."
"Confirm that all tested SIFT descriptors contain 128 values."
]
},
{
Expand Down Expand Up @@ -793,7 +793,7 @@
"\n",
"SIFT detects a different number of keypoints in different images.\n",
"\n",
"It compares the descriptor row counts produced by the tested images."
"Compare the descriptor row counts produced by the tested images."
]
},
{
Expand Down Expand Up @@ -832,7 +832,7 @@
"source": [
"## 14. Final validation\n",
"\n",
"It performs the final checks for the sample SIFT output.\n",
"Perform the final checks for the sample SIFT output.\n",
"\n",
"The number of descriptor rows may vary between images, but every descriptor must contain 128 values."
]
Expand Down Expand Up @@ -891,17 +891,11 @@
"source": [
"## Summary\n",
"\n",
"SIFT keypoints and descriptors were successfully extracted from the sample images.\n",
"SIFT was used to detect local keypoints and extract 128-dimensional descriptors.\n",
"\n",
"- Each SIFT descriptor contains 128 values.\n",
"- The descriptor data type is `float32`.\n",
"- The number of keypoints can be different for each image.\n",
"- `max_features=500` requests approximately 500 of the strongest keypoints.\n",
"- The returned number may be slightly above 500 because one location can produce keypoints with multiple orientations.\n",
"- The keypoint count matches the number of descriptor rows.\n",
"- No missing or infinite values were found.\n",
"Different images produced different numbers of descriptors, so the raw SIFT output does not have a fixed length. Because of this, it cannot be directly added to the current HOG and colour feature vector.\n",
"\n",
"Unlike HOG and the RGB colour histogram, SIFT does not directly produce one fixed-length feature vector for each image. A method such as Bag of Visual Words can later convert the SIFT descriptors into a fixed-length representation for classifier training."
"A method such as Bag of Visual Words would be needed before using SIFT with the traditional classifiers."
]
}
],
Expand Down
Loading