Datasets:
image imagewidth (px) 1.28k 2.69k | label class label 0
classes |
|---|---|
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null | |
null |
Viewpoint-Aware Pig Posture Recognition Dataset
This dataset supports multi-camera, viewpoint-aware pig posture recognition in livestock barn environments. It contains real-world pig images, bounding box annotations, posture class labels, and per-instance camera viewpoint angles (azimuth and elevation) derived from PnP-based camera calibration.
Code: Anil-Bhujel/viewpoint-aware-pig-posture-recognition on GitHub
Dataset Summary
Images were captured from 2 real-world pig pens using 4 cameras per pen β 2 overhead fisheye turret cameras and 2 RGB Orbbec depth cameras β installed at different positions and angles. This multi-viewpoint setting captures natural variation in how postures appear under different camera perspectives.
Each annotation includes:
- A bounding box around an individual pig
- A posture class label (5 classes)
- Camera viewpoint angles (azimuth and elevation) for that pig's position
- The source image filename and resolution
Posture Classes
| Class ID | Label | Description |
|---|---|---|
| 0 | Lateral_lying_left |
Pig lying on its side, left laterally |
| 1 | Lateral_lying_right |
Pig lying on its side, right laterally |
| 2 | Sitting |
Pig in sitting posture |
| 3 | Standing |
Pig standing upright |
| 4 | Sternal_lying |
Pig lying on sternum (chest-down, sphinx-like) |
Dataset Structure
viewpoint_aware_pig_posture_recognition/
βββ train.csv # Training annotations with viewpoint angles
βββ seenVP_test.csv # Test set β seen viewpoints (cameras in training)
βββ unseenVP_test.csv # Test set β unseen viewpoints (held-out cameras)
βββ train_images/ # Training images (full frames, multi-camera)
βββ seenVP_test_images/ # Test images β seen viewpoint cameras
βββ unseenVP_test_images/ # Test images β unseen viewpoint cameras
Dataset Statistics
| Split | Instances | Images |
|---|---|---|
| Train | 22,933 | 3,090 |
| Seen-VP test | 2,603 | 300 |
| Unseen-VP test | 11,708 | 1,350 |
CSV Columns
Each CSV file has the following columns:
| Column | Type | Description |
|---|---|---|
row_id |
str | Unique instance identifier |
image_id |
str | Filename of the source image |
width |
int | Image width in pixels |
height |
int | Image height in pixels |
bbox |
str | Bounding box in [x, y, w, h] format (XYWH, pixel coords) |
class_id |
int | Posture class label (0β4, see table above) |
world_x |
float | Pig floor position X (normalised, floor_width = 1.0) |
world_y |
float | Pig floor position Y (normalised) |
azimuth_deg |
float | Camera-to-pig azimuth angle in degrees (β180 to +180) |
elevation_deg |
float | Camera elevation angle in degrees (zenith convention: 0 = overhead, 90 = horizontal) |
elevation_down_deg |
float | Positive-down elevation (0β90Β°, always overhead positive) |
azimuth_sin |
float | sin(azimuth) β used directly as model feature |
azimuth_cos |
float | cos(azimuth) β used directly as model feature |
elevation_sin |
float | sin(elevation) β used directly as model feature |
elevation_cos |
float | cos(elevation) β used directly as model feature |
angle_valid |
int | 1 = valid angle computed; 0 = outside pen or undistort failed |
cam_pos_source |
str | "pnp" (PnP pipeline) or "config" (manual config pipeline) |
arrow_u |
float | Azimuth direction unit vector X component (visualisation helper) |
arrow_v |
float | Azimuth direction unit vector Y component (visualisation helper) |
The unseen-VP test CSV also includes auxiliary columns incl_class and orient_class for sub-category analysis.
Camera Setup
| Camera ID | Type | Model | Resolution |
|---|---|---|---|
pen1_tur_cam1, pen1_tur_cam2 |
Fisheye | Turret overhead | 1280 Γ 720 |
pen2_tur_cam1, pen2_tur_cam2 |
Fisheye | Turret overhead | 1280 Γ 720 |
pen1_orb_cam1, pen1_orb_cam2 |
Pinhole | Orbbec Femto RGB | 1920 Γ 1080 |
pen2_orb_cam1, pen2_orb_cam2 |
Pinhole | Orbbec Femto RGB | 1920 Γ 1080 |
Camera intrinsics (checkerboard .npz for fisheye cameras and manufacturer .ini for Orbbec pinhole cameras) are available in the companion code repository.
Viewpoint Angle Convention
Angles follow the zenith convention:
- Azimuth (
azimuth_deg): angle of the horizontal projection of the camera-to-pig ray, measured from the +X axis, counter-clockwise positive (β180Β° to +180Β°). - Elevation (
elevation_deg, zenith): 0Β° means the camera is directly overhead the pig; 90Β° means the camera is at the same height as the pig (horizontal line of sight).
The (sin, cos) encoding avoids angle-wrapping discontinuities and is used directly as the four-dimensional angle feature vector [azimuth_sin, azimuth_cos, elevation_sin, elevation_cos] in model training.
How to Load
Using HuggingFace datasets
from datasets import load_dataset
ds = load_dataset("anilbhujel/viewpoint-aware-pig-posture-recognition")
print(ds)
Manual download
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="anilbhujel/viewpoint-aware-pig-posture-recognition",
repo_type="dataset",
local_dir="./dataset"
)
Load CSV + images with pandas
import pandas as pd
from PIL import Image
from pathlib import Path
import ast
data_root = Path("dataset/viewpoint_aware_pig_posture_recognition")
# Load annotations
train_df = pd.read_csv(data_root / "train.csv")
# Parse one bounding box
row = train_df.iloc[0]
bbox = ast.literal_eval(row["bbox"]) # [x, y, w, h]
x, y, w, h = bbox
# Crop the pig from its source image
img_path = data_root / "train_images" / row["image_id"]
img = Image.open(img_path).convert("RGB")
crop = img.crop((x, y, x + w, y + h))
print(f"Class: {row['class_id']}, Azimuth: {row['azimuth_deg']:.1f}Β°, Elevation: {row['elevation_deg']:.1f}Β°")
crop.show()
PyTorch DataLoader
The full training pipeline, PigCropDataset, and all model code live in the companion GitHub repository. Clone it first, then point it at this dataset:
git clone https://github.com/Anil-Bhujel/viewpoint-aware-pig-posture-recognition.git
cd viewpoint-aware-pig-posture-recognition
import sys
sys.path.insert(0, "dino_angles_domain")
from dataset import PigCropDataset
from utils import pad_to_square
import torchvision.transforms as T
val_tfms = T.Compose([
T.Lambda(lambda im: pad_to_square(im, 224)),
T.ToTensor(),
T.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
])
ds = PigCropDataset(
csv_path="dataset/viewpoint_aware_pig_posture_recognition/unseenVP_test.csv",
image_dir="dataset/viewpoint_aware_pig_posture_recognition/unseenVP_test_images",
transform=val_tfms,
use_angles=True, # loads azimuth_sin/cos + elevation_sin/cos from CSV
)
print(f"Dataset size: {len(ds)}")
x, angles, label = ds[0]
print(f"Image shape: {x.shape}, Angles: {angles}, Label: {label}")
Using with the Code Repository
The GitHub repository contains the full pipeline for:
- Camera calibration (PnP from 4 annotated floor corners)
- Per-instance viewpoint angle computation
- DINOv2-based posture classifier training and evaluation
Quick start with this dataset:
# 1. Clone the code
git clone https://github.com/Anil-Bhujel/viewpoint-aware-pig-posture-recognition.git
cd viewpoint-aware-pig-posture-recognition
# 2. Install dependencies
pip install torch torchvision transformers
pip install opencv-python numpy pandas scikit-learn matplotlib seaborn Pillow
# 3. Download this dataset
pip install huggingface_hub
python -c "
from huggingface_hub import snapshot_download
snapshot_download(
repo_id='anilbhujel/viewpoint-aware-pig-posture-recognition',
repo_type='dataset',
local_dir='dataset'
)"
# 4. Train (angle conditioning + domain adversarial)
cd dino_angles_domain
python dino_train.py \
--data-root ../dataset/viewpoint_aware_pig_posture_recognition \
--dino-weight facebook/dinov2-base \
--use-angles --use-domain-adv \
--epochs 30 --batch 64 --lr 1e-4 \
--out-dir runs/angle_domain_adv
For full instructions including camera re-calibration, all training flags, and evaluation, see the code README.
Benchmark Results
Results with the provided best_dino_angle_domain_model.pt checkpoint (DINOv2-base backbone + MLP head + angle conditioning + domain adversarial training):
Seen Viewpoints Test Set
| Class | Precision | Recall | F1 |
|---|---|---|---|
| Lateral lying left | 0.820 | 0.921 | 0.868 |
| Lateral lying right | 0.843 | 0.877 | 0.860 |
| Sitting | 0.844 | 0.771 | 0.806 |
| Standing | 0.986 | 0.985 | 0.985 |
| Sternal lying | 0.904 | 0.855 | 0.879 |
| Macro avg | 0.879 | 0.882 | 0.880 |
| Accuracy | 92.51% |
Unseen Viewpoints Test Set
| Class | Precision | Recall | F1 |
|---|---|---|---|
| Lateral lying left | 0.847 | 0.870 | 0.858 |
| Lateral lying right | 0.867 | 0.859 | 0.863 |
| Sitting | 0.746 | 0.788 | 0.766 |
| Standing | 0.959 | 0.984 | 0.972 |
| Sternal lying | 0.875 | 0.821 | 0.847 |
| Macro avg | 0.859 | 0.864 | 0.861 |
| Accuracy | 91.07% |
Seen vs. Unseen Viewpoint Splits
The dataset is split to evaluate viewpoint generalisation:
- Seen-VP test set: Images from the same camera positions that appear in training. Tests in-distribution performance.
- Unseen-VP test set: Images from camera positions held out from training. Tests how well the model generalises to new camera angles.
The large unseen-VP test set (11,708 instances) provides a realistic evaluation of cross-camera generalisation.
Data Collection
Images were collected from pig barn environments using ceiling- and wall-mounted cameras. Pigs were annotated with bounding boxes and posture labels. Camera calibration parameters were estimated using the PnP algorithm applied to 4 manually annotated pen-floor corner points per camera, without requiring physical measurement of the pen dimensions.
License
This dataset is released under the Creative Commons Attribution 4.0 (CC BY 4.0) license.
Citation
If you use this dataset, please cite:
@inproceedings{CV4Animals2026,
title = {Viewpoint-Aware Pig Posture Recognition and Benchmark Dataset},
author = {Bhujel, Anil, Bashar Mk, and Morris, Daniel},
year = {2026}
}
- Downloads last month
- 1,176
