Commit ·
d541e6d
0
Parent(s):
Revert last upload
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributesAdded+61
- Ground Truth/mustard_train.csvAdded
- Ground Truth/okra_train.csvAdded
- Ground Truth/radish_train.csvAdded
- Ground Truth/wheat_train.csvAdded
- README.mdAdded+195
- Test_data/For_age_prediction/Ground truth/mustard_test.csvAdded
- Test_data/For_age_prediction/Ground truth/okra_test.csvAdded
- Test_data/For_age_prediction/Ground truth/radish_test.csvAdded
- Test_data/For_age_prediction/Ground truth/wheat_test.csvAdded
- Test_data/For_age_prediction/Ground truth/wheat_test1.csvAdded
- Test_data/For_age_prediction/acm_test_py.pyAdded+336
- Test_data/For_age_prediction/augmented_leaf_data (1).csvAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_0.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_105.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_120.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_135.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_15.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_150.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_165.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_180.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_195.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_210.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_225.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_240.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_255.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_270.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_285.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_30.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_300.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_315.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_330.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_345.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_45.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_60.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_75.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_90.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_0.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_105.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_120.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_135.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_15.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_150.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_165.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_180.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_195.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_210.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_225.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_240.pngAdded
- Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_255.pngAdded
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.avro filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.lz4 filter=lfs diff=lfs merge=lfs -text*.mds filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text# Audio files - uncompressed*.pcm filter=lfs diff=lfs merge=lfs -text*.sam filter=lfs diff=lfs merge=lfs -text*.raw filter=lfs diff=lfs merge=lfs -text# Audio files - compressed*.aac filter=lfs diff=lfs merge=lfs -text*.flac filter=lfs diff=lfs merge=lfs -text*.mp3 filter=lfs diff=lfs merge=lfs -text*.ogg filter=lfs diff=lfs merge=lfs -text*.wav filter=lfs diff=lfs merge=lfs -text# Image files - uncompressed*.bmp filter=lfs diff=lfs merge=lfs -text*.gif filter=lfs diff=lfs merge=lfs -text*.png filter=lfs diff=lfs merge=lfs -text*.tiff filter=lfs diff=lfs merge=lfs -text# Image files - compressed*.jpg filter=lfs diff=lfs merge=lfs -text*.jpeg filter=lfs diff=lfs merge=lfs -text*.webp filter=lfs diff=lfs merge=lfs -text# Video files - compressed*.mp4 filter=lfs diff=lfs merge=lfs -text*.webm filter=lfs diff=lfs merge=lfs -textTest_data/For_leaf_counting/okra/p1/d22/L2/PXL_20230808_110153626_6.dng filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195---license: cc-by-4.0task_categories:- image-classification- text-to-image- image-to-textlanguage:- entags:- plant-growth- phenotyping- agriculture- multiview- time-series- leaf-counting- age-estimation- precision-agriculturepretty_name: GroMo 25 — Multiview Plant Growth Datasetsize_categories:- 10K<n<100K---
# GroMo25: Multiview Time-Series Plant Image Dataset for Age Estimation and Leaf Counting
## Dataset Summary
**GroMo25** is a multiview, time-series plant image dataset designed for plant age estimation (in days) and leaf counting tasks in precision agriculture. It contains high-quality images of four crop species — **Wheat, Okra, Radish, and Mustard** — captured over multiple days under controlled conditions. Each plant is photographed from 24 angles across 5 vertical levels per day, providing rich spatial and temporal information for plant growth modeling.
This dataset is intended for researchers and practitioners in **academic research, plant phenotyping, and agriculture**, and serves as the official dataset for the **GroMo Challenge**.
> **Paper:** [GroMo Challenge: Multiview time-series plant image dataset for age estimation and leaf counting in precision agriculture](https://dl.acm.org/doi/abs/10.1145/3746027.3762097)
---
## Dataset Structure
### Crops Included
| Crop | Description ||---------|-----------------------------------------|| Wheat | Cereal crop, multiple growth stages || Okra | Vegetable crop, leaf-heavy growth || Radish | Root vegetable, rapid growth cycle || Mustard | Oilseed crop, distinct leaf pattern |
### Image Capture Setup
All images were captured in a **controlled indoor environment**:- Each plant is grown in a **pot** placed on a **rotating disk**- The background is covered with a **white cloth** to ensure clean segmentation and consistent background- Images are taken at **24 angles** per level (0° to 345°, 15° increment between consecutive angles)- Each plant is photographed across **5 vertical levels** (L1 to L5) per day
### Images Per Day (Per Plant)
```5 levels × 24 angles = 120 images per plant per day```
### Directory Structure
```dataset/├── train/│ ├── p1/│ │ ├── d1/│ │ │ ├── L1/│ │ │ │ ├── radish_p1_d1_L1_0.png│ │ │ │ ├── radish_p1_d1_L1_15.png│ │ │ │ ├── ...│ │ │ │ └── radish_p1_d1_L1_345.png│ │ │ ├── L2/│ │ │ ├── L3/│ │ │ ├── L4/│ │ │ └── L5/│ │ ├── d2/│ │ └── ...│ ├── p2/│ ├── p3/│ └── p4/└── test/ └── (same structure as train)```
### File Naming Convention
Each image follows the format:
```{crop}_p{X}_d{Y}_L{Z}_{A}.png```
| Field | Description ||-------|-------------|| `crop` | Crop name (e.g., `radish`, `wheat`) || `X` | Plant ID (e.g., `p1`, `p2`) || `Y` | Day number (e.g., `d1`, `d2`) || `Z` | Level (L1 to L5) || `A` | Angle in degrees (0 to 345, step 15) |
**Example:** `radish_p1_d3_L2_90.png` → Radish, Plant 1, Day 3, Level 2, angle 90°
---
## Ground Truth / Annotations
Each crop has a corresponding `{crop}_train.csv` file containing per-image labels.
### Format
| Column | Description ||--------|-------------|| `filename` | Relative path to the image || `leaf_count` | Number of leaves on the plant || `Age` | Age of the plant in days |
### Example```csvfilename,leaf_count,Agemustard/p1/d1/L1/mustard_p1_d1_L1_0.png,2,1```
A separate CSV is provided for each crop covering all plants, days, levels, and angles.
---
## Tasks
This dataset supports the following tasks:
- **Plant Age Estimation** — Predict the number of days since planting (regression)- **Leaf Counting** — Predict the number of leaves visible on the plant (regression)
### Evaluation Metrics
| Metric | Description ||--------|-------------|| RMSE | Root Mean Squared Error || MAE | Mean Absolute Error |
---
## Citation
If you use this dataset in your research, please cite:
```bibtex@inproceedings{10.1145/3746027.3762097,author = {Bansal, Shreya and Bhatt, Ruchi and Chander, Amanpreet and Kaur, Rupinder and Singh, Malya and Kankanhalli, Mohan and El Saddik, Abdulmotaleb and Saini, Mukesh},title = {GroMo25: ACM Multimedia 2025 Grand Challenge for Plant Growth Modeling with Multiview Images},year = {2025},isbn = {9798400720352},publisher = {Association for Computing Machinery},address = {New York, NY, USA},url = {https://doi.org/10.1145/3746027.3762097},doi = {10.1145/3746027.3762097},abstract = {Understanding plant growth dynamics is a critical component of modern agricultural research, with applications in yield prediction, phenotyping, and sustainable crop management. Despite recent advances in computer vision and deep learning, progress in plant growth modeling has been constrained by the lack of publicly available, high-resolution, multiview, and temporally rich datasets. To address this gap, we introduce Growth Modelling GroMo25, the first international challenge on plant growth modeling using multiview imagery. In this challenge, we propose a dataset that comprises high-resolution images of four crops: wheat, mustard, radish, and okra, captured at consistent time intervals from multiple camera viewpoints under controlled environmental conditions. The challenge focuses on two key tasks: (1) plant age prediction and (2) leaf count estimation, both requiring models to use spatial and temporal plant features. GroMo25 attracted participation from multiple teams worldwide, encouraging benchmarking and innovation in vision-based plant phenotyping. The GitHub repository is publicly available at https://github.com/mriglab/GroMo-Plant-Growth-Modeling-with-Multiview-Images.},booktitle = {Proceedings of the 33rd ACM International Conference on Multimedia},pages = {14204–14209},numpages = {6},keywords = {growth age prediction, leaf count estimation, multiview},location = {Dublin, Ireland},series = {MM '25}}```
---
## Authors & Affiliations
| Name | Institution ||------|------------|| Shreya Bansal | IIT Ropar || Ruchi Bhatt | IIT Ropar || Amanpreet Chander | IIT Ropar || Rupinder Kaur | IIT Ropar || Malya Singh | IIT Ropar || Dr. Mohan Kankanhalli | National University of Singapore || Abdulmotaleb El Saddik | University of Ottawa || Mukesh Kumar Saini | IIT Ropar |
For queries, contact: **mrig@iitrpr.ac.in**
---
## License
This dataset is released under the [Creative Commons Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/) license.
You are free to use, share, and adapt this dataset for any purpose, including commercial use, as long as appropriate credit is given to the authors.
---
## NoteThe dataset is part of a challenge organised by [ANNAM.AI](http://data.annam.ai/gromo25/)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336# -*- coding: utf-8 -*-"""acm_test.py.ipynb
Automatically generated by Colab.
Original file is located at https://colab.research.google.com/drive/1iMB_SLHX4vbCzsA_7Q8MJe-SSKX4Cphr"""
from google.colab import drivedrive.mount('/content/drive')
import torchimport torch.nn as nnimport torch.optim as optimfrom torch.utils.data import Dataset, DataLoader, random_splitfrom torchvision import transformsimport osfrom PIL import Imageimport randomimport numpy as npfrom tqdm import tqdmimport matplotlib.pyplot as pltimport pandas as pdfrom sklearn.metrics import r2_score, mean_absolute_error
# Define the device (GPU or CPU)device = torch.device("cuda" if torch.cuda.is_available() else "cpu")print(device)
################################# Input here ###################################root_path='/content/drive/MyDrive/ACM grand challenge/Test_data/For_age_prediction/'csv_file='/content/okra_test.csv'crop='okra'n_images=4plant_input=2days_input=86batch_size = 8seed=42height, width = 224, 224# Transformations for resizing and converting to tensortransform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])##############################################################################
class CropDataset(Dataset): def __init__(self, root_dir, csv_file, images_per_level, crop, plants, days, levels=['L1', 'L2', 'L3', 'L4', 'L5'], transform=None): """ Args: root_dir (str): Directory with all the images. csv_file (str): Path to the CSV file containing ground truth (filename, leaf_count, age). images_per_level (int): Number of images to select per level (should be factors of 24). crop (str): Crop type (e.g., "radish"). plants (int): Number of plants (e.g., 4). days (int): Number of days (e.g., 59). levels (list): List of levels (e.g., ['L1', 'L2', 'L3', 'L4', 'L5']). transform (callable, optional): Transform to be applied on a sample. """ self.root_dir = root_dir self.csv_file = csv_file self.images_per_level = images_per_level self.crop = crop self.plants_num = plants self.max_days = days self.levels = levels self.transform = transform self.image_data = self._load_metadata() self.image_paths = self._load_image_paths()
def _load_metadata(self): """Load CSV file into a pandas DataFrame and map filenames to leaf counts and ages.""" df = pd.read_csv(self.csv_file) df["filename"] = df["filename"].astype(str) # Ensure filenames are strings return df.set_index("filename") # Use filename as the index for quick lookup
def _select_angles(self): """ Select angles dynamically for a given level. """ images_needed = self.images_per_level selected_angles = [i for i in range(0, 360, int(360 / images_needed))]
initial_angles = [i for i in range(15, selected_angles[1], 15)] multiple_selections = [selected_angles]
for initial_angle in initial_angles: selection = [initial_angle] while len(selection) < images_needed: next_angle = (selection[-1] + int(360 / images_needed)) % 360 if next_angle not in selection: selection.append(next_angle) multiple_selections.append(selection) print(multiple_selections) return multiple_selections
def _load_image_paths(self): """ Load image paths for all levels and plants based on the selection of angles. """ image_paths = [] multiple_selections = self._select_angles()
for plant in range(1, self.plants_num + 1): plant_path = os.path.join(self.root_dir, crop, f"p{plant}") if not os.path.isdir(plant_path): print(f"Plant directory not found: {plant_path}") continue for day in range(1, self.max_days + 1): day_path = os.path.join(self.root_dir, crop, f"p{plant}", f"d{day}") if not os.path.isdir(day_path): continue for selected_angles in multiple_selections: for level in self.levels: level_path = os.path.join(self.root_dir,self.crop, f"p{plant}", f"d{day}", level) level_image_paths = [ os.path.join(level_path, f"{self.crop}_p{plant}_d{day}_{level}_{angle}.png") for angle in selected_angles ] filename = os.path.join(self.crop,f"p{plant}", f"d{day}", level,f"{self.crop}_p{plant}_d{day}_{level}_{selected_angles[0]}.png") print(filename) leaf_count = self.image_data.loc[filename, "leaf_count"] # print(level_image_paths) image_paths.append((level_image_paths, leaf_count,day)) # Append day number along with image paths
print(f"Total samples loaded: {len(image_paths)}") # print(f"individual sample size: {len(image_paths[0][0])}") return image_paths
def __len__(self): return len(self.image_paths)
def __getitem__(self, idx): """ Get a batch of images from the dataset corresponding to the angles selected. """ images = [] leaf_count = self.image_paths[idx][1] age = self.image_paths[idx][2] # print(leaf_count,age) all_images= self.image_paths[idx][0] # print("length of all images:", len(all_images)) for img_path in all_images: # Get the image paths for this sample if os.path.isfile(img_path): level_image = Image.open(img_path) if self.transform: level_image = self.transform(level_image) images.append(level_image) else: print(f"Path is not a valid file: {img_path}")
images = torch.cat(images, dim=0)
return images, torch.tensor(leaf_count, dtype=torch.float32), torch.tensor(age, dtype=torch.float32) # Return both images and the corresponding day as ground truth
test_dataset = CropDataset(root_dir=root_path, csv_file=csv_file, images_per_level=n_images, crop=crop, plants=plant_input, days=days_input, transform=transform)
num_images = n_images # Number of images (24 RGB images)input_channels = num_images*3 # 24 RGB images (3 channels each)patch_size = 16 # Size of each patchnum_patches = (height // patch_size) * (width // patch_size) # Number of patches (14 * 14 for 224x224 images)projection_dim = 256 # Embedding dimension for each patchnum_heads = 8 # Number of attention headsnum_layers = 6 # Number of transformer layersmlp_dim = 512 # Dimension of the MLP headnum_classes = 1 # Number of output classes (for day or leaf count prediction)dropout_rate = 0.1 # Dropout rate
# DataLoader for training and validation setstest_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=True)
class VisionTransformer(nn.Module): def __init__(self, input_channels, patch_size, num_patches, projection_dim, num_heads, num_layers, mlp_dim, num_images, dropout_rate=0.1): super(VisionTransformer, self).__init__()
self.num_images = num_images # Total number of images (24 images in your case) self.patch_size = patch_size self.num_patches = num_patches self.projection_dim = projection_dim self.num_heads = num_heads self.num_layers = num_layers self.mlp_dim = mlp_dim
# Separate patch embedding layers for each image (RGB) self.patch_embeds = nn.ModuleList([ nn.Conv2d(input_channels // num_images, projection_dim, kernel_size=patch_size, stride=patch_size) for _ in range(num_images) ])
# Positional Encoding (Learnable) self.positional_encoding = nn.Parameter(torch.randn(1, num_patches, projection_dim))
# Transformer Encoder Layers (modified to return attention weights) self.attention_layers = nn.ModuleList([ nn.TransformerEncoderLayer( d_model=projection_dim, nhead=num_heads, dim_feedforward=mlp_dim, dropout=dropout_rate, batch_first=True ) for _ in range(num_layers) ])
# MLP Head for classification/regression self.mlp_head = nn.Sequential( nn.Linear(projection_dim * num_images, mlp_dim), nn.ReLU(), nn.Linear(mlp_dim, 1) )
def forward(self, x): batch_size = x.shape[0]
# Step 1: Patch Embedding (Separate for each image) patch_embeddings = [] for i in range(self.num_images): # Split the input channels into separate images (3 channels each for RGB) img_x = x[:, i*3:(i+1)*3, :, :] # Shape: (batch_size, 3, height, width) patch_embed = self.patch_embeds[i](img_x) # Apply separate embedding patch_embed = patch_embed.flatten(2).transpose(1, 2) # Shape: (batch_size, num_patches, projection_dim) patch_embeddings.append(patch_embed)
# Step 2: Add Positional Encoding patch_embeddings = [pe + self.positional_encoding for pe in patch_embeddings]
# Step 3: Transformer Encoder Layers (Self-attention + Feed Forward) attention_weights = [] # To store attention weights for layer in self.attention_layers: layer_attention_weights = [] # Store the attention weights for each layer for i in range(self.num_images): # Modified to return attention weights (self-attention) attn_output, attn_weights = layer.self_attn(patch_embeddings[i], patch_embeddings[i], patch_embeddings[i]) patch_embeddings[i] = attn_output layer_attention_weights.append(attn_weights) attention_weights.append(layer_attention_weights)
# Step 4: Concatenate the projections from each image (Shape: (batch_size, num_patches, projection_dim * num_images)) x = torch.cat(patch_embeddings, dim=-1) # Concatenate across the last dimension (projection_dim)
# Step 5: Pooling (Take mean across all patches) x = x.mean(dim=1) # Mean pooling over patches (Shape: (batch_size, projection_dim * num_images))
# Step 6: MLP Head for classification/regression output = self.mlp_head(x)
return output, attention_weights # Return attention weights too
# Load the trained modelmodel_path = "/content/drive/MyDrive/ACM grand challenge/Crops data/For_age_prediction/results/okra_all files/okra_vit_age_prediction_10.pth" # Change this to your actual model pathdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Assuming your model class is defined as MyModelmodel = VisionTransformer(input_channels, patch_size, num_patches, projection_dim, num_heads, num_layers, mlp_dim, num_images, dropout_rate) # Replace with your actual model classmodel.load_state_dict(torch.load(model_path, map_location=device))model.to(device)model.eval() # Set model to evaluation mode
# Initialize lists to store predictions and actual valuesy_true = []y_pred = []
# Run inference on the test setwith torch.no_grad(): for images, count, age in test_loader: # Assuming test_loader gives (images, labels) images = images.to(device) count = count.to(device) age = age.to(device)
outputs, attention = model(images) # Ensure outputs are properly shaped y_true.extend(age.cpu().numpy()) y_pred.extend(outputs.cpu().numpy())
# Convert to NumPy arraysy_true = np.array(y_true)y_pred = np.array(y_pred)
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score# Compute metricsrmse = np.sqrt(mean_squared_error(y_true, y_pred))mae = mean_absolute_error(y_true, y_pred)r2 = r2_score(y_true, y_pred)
# Print resultsprint(f"RMSE: {rmse:.4f}")print(f"MAE: {mae:.4f}")print(f"R² Score: {r2:.4f}")
# Load the trained modelmodel_path = "/content/drive/MyDrive/ACM grand challenge/Crops data/For_age_prediction/results/okra_all files/okra_vit_leaf_count_8.pth" # Change this to your actual model pathdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Assuming your model class is defined as MyModelmodel = VisionTransformer(input_channels, patch_size, num_patches, projection_dim, num_heads, num_layers, mlp_dim, num_images, dropout_rate) # Replace with your actual model classmodel.load_state_dict(torch.load(model_path, map_location=device))model.to(device)model.eval() # Set model to evaluation mode
# Initialize lists to store predictions and actual valuesy_true = []y_pred = []
# Run inference on the test setwith torch.no_grad(): for images, count, age in test_loader: # Assuming test_loader gives (images, labels) images = images.to(device) count = count.to(device) count = count.to(device)
outputs, attention = model(images) # Ensure outputs are properly shaped y_true.extend(count.cpu().numpy()) y_pred.extend(outputs.cpu().numpy())
# Convert to NumPy arraysy_true = np.array(y_true)y_pred = np.array(y_pred)from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score# Compute metricsrmse = np.sqrt(mean_squared_error(y_true, y_pred))mae = mean_absolute_error(y_true, y_pred)r2 = r2_score(y_true, y_pred)
# Print resultsprint(f"RMSE: {rmse:.4f}")print(f"MAE: {mae:.4f}")print(f"R² Score: {r2:.4f}").gitattributesAdded+61
Ground Truth/mustard_train.csvAdded
Ground Truth/okra_train.csvAdded
Ground Truth/radish_train.csvAdded
Ground Truth/wheat_train.csvAdded
README.mdAdded+195
Test_data/For_age_prediction/Ground truth/mustard_test.csvAdded
Test_data/For_age_prediction/Ground truth/okra_test.csvAdded
Test_data/For_age_prediction/Ground truth/radish_test.csvAdded
Test_data/For_age_prediction/Ground truth/wheat_test.csvAdded
Test_data/For_age_prediction/Ground truth/wheat_test1.csvAdded
Test_data/For_age_prediction/acm_test_py.pyAdded+336
Test_data/For_age_prediction/augmented_leaf_data (1).csvAdded
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_0.pngAdded

Large File Pointer Details
- SHA256: 437fe117c52eecb0bf8e5f2250774c826def236bc676dbb715b0d1e848c7c5fc
- Pointer size: 132 Bytes
- Size of remote file: 2.73 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_105.pngAdded

Large File Pointer Details
- SHA256: a50405042a63a2964e2f4d952840dfb5d6b7cfa5219119ea5c2fcf013575d7a2
- Pointer size: 132 Bytes
- Size of remote file: 2.68 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_120.pngAdded

Large File Pointer Details
- SHA256: 698b9bc11128367cbfee4922b5562b55b166639272248e4301a705587ec29f49
- Pointer size: 132 Bytes
- Size of remote file: 2.55 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_135.pngAdded

Large File Pointer Details
- SHA256: c0edc6cf30fee5521c432b9b9694e6dab5856aef542670db207135a3ded28e4a
- Pointer size: 132 Bytes
- Size of remote file: 2.35 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_15.pngAdded

Large File Pointer Details
- SHA256: bc07db5cc5d51c07e282e364e4f1aecff13c81a64d6e8dbc931d8d6fe13a6bff
- Pointer size: 132 Bytes
- Size of remote file: 2.45 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_150.pngAdded

Large File Pointer Details
- SHA256: 050db8c58a0340b360923a1ae1802680b21d5f88d9cb6e52e11687b839a999d2
- Pointer size: 132 Bytes
- Size of remote file: 2.39 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_165.pngAdded

Large File Pointer Details
- SHA256: 11b0878be478555641610fef35cd1acd646516b3b3fcaded48de98fe6030351e
- Pointer size: 132 Bytes
- Size of remote file: 2.32 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_180.pngAdded

Large File Pointer Details
- SHA256: 5625718b4375bd5b5087cd7a14622361151faee4c3c691e6e07ed99fdce0397a
- Pointer size: 132 Bytes
- Size of remote file: 2.32 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_195.pngAdded

Large File Pointer Details
- SHA256: e15dbe9c96b031f0ea900fd7f3a6fbc61358562c91fa6cae2c5af4fec61421ad
- Pointer size: 132 Bytes
- Size of remote file: 2.68 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_210.pngAdded

Large File Pointer Details
- SHA256: f66a583656345eb3a2c52632ebc8f645589e3a7ba68b8e9bf5e5c250d380ad45
- Pointer size: 132 Bytes
- Size of remote file: 2.23 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_225.pngAdded

Large File Pointer Details
- SHA256: 62d44d5a79f31c3057a1bdc7344feb86c752cbca94f375b94b860e3338bef6a0
- Pointer size: 132 Bytes
- Size of remote file: 2.34 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_240.pngAdded

Large File Pointer Details
- SHA256: 6a4d148328869eb76ae9426f426766f7b7f854665b8e83fba8830877e631e163
- Pointer size: 132 Bytes
- Size of remote file: 2.93 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_255.pngAdded

Large File Pointer Details
- SHA256: e5f3d0855c4bba90f863348afb2e284e0878ca6bb1cd0e359f54c43f9f649f90
- Pointer size: 132 Bytes
- Size of remote file: 2.69 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_270.pngAdded

Large File Pointer Details
- SHA256: 351fa4f3794699ff37968842131657309cba69a286de3c4248a6d067057f2bc6
- Pointer size: 132 Bytes
- Size of remote file: 2.67 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_285.pngAdded

Large File Pointer Details
- SHA256: d669511502750b95f82b2cb548b59885b3694a76731ff177b921e651261e867b
- Pointer size: 132 Bytes
- Size of remote file: 2.65 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_30.pngAdded

Large File Pointer Details
- SHA256: ea0ab5afd6343ed0b94362823de53a9c2ab61046d7ff31c442836948dc50e8a1
- Pointer size: 132 Bytes
- Size of remote file: 2.48 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_300.pngAdded

Large File Pointer Details
- SHA256: 09bb17e2f4f0675c2c3390383e7ed9bed1b243abf7f0647f97e1cbd5d676d611
- Pointer size: 132 Bytes
- Size of remote file: 2.63 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_315.pngAdded

Large File Pointer Details
- SHA256: 376b769f19a9c659ddfd7e94de8c4d90850cd1f0fbaedec601440abd42181580
- Pointer size: 132 Bytes
- Size of remote file: 3.04 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_330.pngAdded

Large File Pointer Details
- SHA256: 541c967368850507f27fd4d59316090d9c81ee414e8a0d42933599e87b29cad2
- Pointer size: 132 Bytes
- Size of remote file: 2.72 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_345.pngAdded

Large File Pointer Details
- SHA256: eeb83a94e3ac3105d8d25866c5d77c058290b91da395e567bb7ee96fc1b7b240
- Pointer size: 132 Bytes
- Size of remote file: 3.21 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_45.pngAdded

Large File Pointer Details
- SHA256: addf1609341b8b27e29e7c85a70856e1b5024bff94f4f0680b31eb4e2105bdd3
- Pointer size: 132 Bytes
- Size of remote file: 2.61 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_60.pngAdded

Large File Pointer Details
- SHA256: 2814d2cdce820cdde02d986e92f1c680a6cc3bc47f35d362bbd40fb7b1fb641e
- Pointer size: 132 Bytes
- Size of remote file: 2.43 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_75.pngAdded

Large File Pointer Details
- SHA256: d9be835efafd91e153c54c4d2324f7438127a20f6579b8a39c99b70b376cdae9
- Pointer size: 132 Bytes
- Size of remote file: 2.37 MB
Test_data/For_age_prediction/mustard/p4/d1/L1/mustard_p4_d1_L1_90.pngAdded

Large File Pointer Details
- SHA256: 724c55d16d40e4bef4fd342d313f7b457071719415e168f385ceb8b9264d07bb
- Pointer size: 132 Bytes
- Size of remote file: 2.59 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_0.pngAdded

Large File Pointer Details
- SHA256: 633cf46faa3b4dc984490003276264fbd2eeeb553bb6b5a6b63a9e9da002f540
- Pointer size: 132 Bytes
- Size of remote file: 2.87 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_105.pngAdded

Large File Pointer Details
- SHA256: 5c97c3b8c01db93e3d787d0e1394011eed1f259534a0b9c658e58f569aee7883
- Pointer size: 132 Bytes
- Size of remote file: 2.9 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_120.pngAdded

Large File Pointer Details
- SHA256: 6b4c9c239050cb1ff98f0536af74fe3f964af194c7824d01bf1a8cc0e60e3aa9
- Pointer size: 132 Bytes
- Size of remote file: 3.03 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_135.pngAdded

Large File Pointer Details
- SHA256: f5e2817e1311443b5e2c04870ae08c5ea581d120115a21b481704bedcba96994
- Pointer size: 132 Bytes
- Size of remote file: 2.92 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_15.pngAdded

Large File Pointer Details
- SHA256: a404eb20e5776045e439d64c0e668b0a0618e2ba8e5453c93aa486a52d10f482
- Pointer size: 132 Bytes
- Size of remote file: 2.72 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_150.pngAdded

Large File Pointer Details
- SHA256: fa5ab5b3613114ad25a86e0ff43760f5260ab02c2252a4e9ee9e36127eae27b2
- Pointer size: 132 Bytes
- Size of remote file: 2.86 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_165.pngAdded

Large File Pointer Details
- SHA256: b9ce592a3244b9aa91dc1c2d1b259f4803844b0a4e2e555ae22dc2c7c125c712
- Pointer size: 132 Bytes
- Size of remote file: 3.09 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_180.pngAdded

Large File Pointer Details
- SHA256: 128d26be382642101979e852b5a9d8a80eb7718e2662a3a9762c95e254fb667d
- Pointer size: 132 Bytes
- Size of remote file: 2.72 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_195.pngAdded

Large File Pointer Details
- SHA256: 782d1cb06d420c66254c9289c5f75676664ac10e11a119e34ea00c4c9b92cadb
- Pointer size: 132 Bytes
- Size of remote file: 2.76 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_210.pngAdded

Large File Pointer Details
- SHA256: 766a1c2058b4a88d9a86cb74dc486f8d7ce6dca6d35f505682a4f6f9720eb033
- Pointer size: 132 Bytes
- Size of remote file: 2.73 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_225.pngAdded

Large File Pointer Details
- SHA256: 5996dc682d5624d2acbddbedc18247b6e7e082accc38aa09317af030bbff8883
- Pointer size: 132 Bytes
- Size of remote file: 2.6 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_240.pngAdded

Large File Pointer Details
- SHA256: 8db3b74241bbc6ae9cda45dd3e99994f40934bb3842bf10d5f7ff6c4c8e5f6c0
- Pointer size: 132 Bytes
- Size of remote file: 2.57 MB
Test_data/For_age_prediction/mustard/p4/d1/L2/mustard_p4_d1_L2_255.pngAdded

Large File Pointer Details
- SHA256: bcfbdbcd6835fc1a1c2354b4b7eb18d27895ab4c9492291dbbed566ed852f6cc
- Pointer size: 132 Bytes
- Size of remote file: 2.66 MB