separated train and test transformation

This commit is contained in:
2026-05-01 23:36:25 +02:00
parent 9285ede90a
commit 07e8563c5d
4 changed files with 56 additions and 22 deletions

35
Tune.py
View File

@@ -8,15 +8,15 @@ from IdentitySubset import IdentitySubset
from architectures.Model import Model, Architecture
# numbre of classes
CLASS_SIZE = 30
CLASS_SIZE = 20
# batch
BATCH_SIZE = 16
BATCH_SIZE = 8
# size of images per class trainset + testset
# 30 works best, more than that and we dont have enough data
SAMPLE_SIZE = 30
# this is then full sample - test sample
# this is then (full_sample - test_sample)
TRAINING_SMPLE = 28
# learning rate
@@ -26,14 +26,18 @@ EPOCHS = 20
# depends on model architecture
# ResNet, DenseNet = 224
# Inception = 299
RESOLUTION = 299
RESOLUTION = 224
# model architecture
arch = Architecture.INCEPTION
# model architecture options are
# - RESNET18
# - RESNET50
# - DENSENET121
# - INCEPTION
arch = Architecture.RESNET18
# DATA PREPARATION
# load data set and prepare
dataset = get_set(res = RESOLUTION)
dataset = get_set()
# select identities for experiment
selected_identities = select_ids(
dataset = dataset,
@@ -56,10 +60,12 @@ id_map = {old_id: new_id for new_id, old_id in enumerate(selected_identities)}
# we remap identities because crossEntropyLoss requires in indices 0 -> (n-1)
# where n = class size.
tr_transform = train_transform(res = RESOLUTION)
train_data = IdentitySubset(
dataset,
train_indices,
id_map)
dataset=dataset,
indices=train_indices,
id_mapping=id_map,
transform=tr_transform)
train_loader = DataLoader(
train_data,
@@ -94,11 +100,14 @@ torch.save(
print('Model saved!')
# EVALUATE
te_transform = test_transform(RESOLUTION)
# Testing
test_data = IdentitySubset(
dataset,
test_indices,
id_map)
dataset = dataset,
indices=test_indices,
id_mapping=id_map,
transform=te_transform)
test_loader = DataLoader(
test_data,