Skip to content

Commit 904c6ce

Browse files
authored
Merge pull request #20 from DaddyWesker/main
Readme added snd some fixes
2 parents 61f2308 + 67ce03f commit 904c6ce

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

vla/benchmarks/block_type_classification/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ Implements the **training and evaluation pipeline**.
3131
- Accuracy for type classification
3232
- Provides helper function:
3333
- `extract_features_size(model, loader)` – determines the classifier input dimension dynamically.
34-
34+
- For benchmark purposes contains `benchmark` function
35+
- Required input parameters:
36+
- **model** is the model which used to extract features from the image tensor. Must contain `encode` function which takes image tensor as input and outputs features.
37+
- **preprocessor** is the preprocessor sequence which is applied to the input image. Preprocessor sequence must contain `T.ToTensor()` and may contain resize, normalize etc.
38+
- either **train_json** and **test_json** or **random_seed**. In one case, dataset is pre-prepared and saved into json files (see **dataset_index_creation_example.py**). In case of **random_seed** as input dataset is being created in the runtime so no need in json files.
39+
- Optional input parameters:
40+
- **label_type** either `LabelType.DISTANCE` or `LabelType.TYPE_CLASSIFICATION` (from `config.py`). Depends on this parameter, classifier or regression model will be created and trained.
41+
- **use_precomputed_features** if set to True, features for all input images will be pre-computed and saved to prevent feature computing while train and test. That helps to reduce time needed to run benchmark. Though requires lots of disk space (depends on which features are used).
42+
- **generalization_set_folder** is used to test generalization capability of the trained model. This folder will be used only to compute accuracy/mse in the end of training process.
43+
- **config_path** path to the json file which contains parameters used to create and train model. Also contains pathes to the dataset folder and folder which will contain precomputed features. See `example.json`.
3544
---
3645

3746
## 🟩 **model.py**
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from manager import DatasetManager
2-
from config import LabelType, PATH_TO_RAW_DATA
2+
from config import LabelType
33

44

55
if __name__ == "__main__":
66
manager = DatasetManager(
7-
directory=PATH_TO_RAW_DATA,
7+
directory="./2025_LOS/Day_clear/",
88
label_type=LabelType.DISTANCE,
99
dataset_size=200,
1010
train_split=0.25,
1111
num_bins=50
1212
)
1313

14-
train_file, test_file = manager.create("los_dataset")
14+
train_file, test_file = manager.create("los_dataset")

vla/benchmarks/block_type_classification/train.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,33 @@ def train_classifier(
7777
avg_train = total_loss / len(train_loader)
7878
print(f"[Epoch {epoch+1}] Train Loss: {avg_train:.4f}")
7979

80-
classifier.eval()
81-
total_test = 0
82-
with torch.no_grad():
83-
for labels, images in test_loader:
84-
images, labels = images.to(device), labels.to(device)
85-
if train_loader.dataset.feature_store is None:
86-
feats = model.encode(images)
87-
else:
88-
feats = images
89-
feats = feats.to(torch.float32)
90-
out = classifier(feats)
91-
total_test += criterion(out, labels).item()
92-
93-
avg_test = total_test / len(test_loader)
94-
print(f"[Epoch {epoch+1}] Test Loss: {avg_test:.4f}")
95-
96-
if avg_test < best_loss:
97-
best_loss = avg_test
98-
torch.save({
99-
"epoch": epoch,
100-
"model_state": classifier.state_dict(),
101-
"optimizer_state": optimizer.state_dict(),
102-
"test_loss": best_loss
103-
}, best_path)
104-
print(f"Saved BEST checkpoint at epoch {epoch+1}{best_path}")
80+
if epoch % 5 == 0:
81+
print(f"Testing, epoch {epoch+1}")
82+
classifier.eval()
83+
total_test = 0
84+
with torch.no_grad():
85+
for labels, images in test_loader:
86+
images, labels = images.to(device), labels.to(device)
87+
if train_loader.dataset.feature_store is None:
88+
feats = model.encode(images)
89+
else:
90+
feats = images
91+
feats = feats.to(torch.float32)
92+
out = classifier(feats)
93+
total_test += criterion(out, labels).item()
94+
95+
avg_test = total_test / len(test_loader)
96+
print(f"[Epoch {epoch+1}] Test Loss: {avg_test:.4f}")
97+
98+
if avg_test < best_loss:
99+
best_loss = avg_test
100+
torch.save({
101+
"epoch": epoch,
102+
"model_state": classifier.state_dict(),
103+
"optimizer_state": optimizer.state_dict(),
104+
"test_loss": best_loss
105+
}, best_path)
106+
print(f"Saved BEST checkpoint at epoch {epoch+1}{best_path}")
105107

106108
# Save last epoch (always)
107109
torch.save({

0 commit comments

Comments
 (0)