-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.py
51 lines (42 loc) · 1.17 KB
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from util import *
import albumentations as A
from albumentations.pytorch import ToTensorV2
from model.model import Conv_AE_LSTM
LEARNING_RATE = 1e-6
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
BATCH_SIZE = 1
NUM_EPOCHS = 35
NUM_WORKERS = 1
IMAGE_HEIGHT = 480
IMAGE_WIDTH = 850
PIN_MEMORY = True
LOAD_MODEL = True
TRAIN_DIR ='/y/ayhassen/anomaly_detection/shanghaitech/training_set/frames'
VAL_DIR ='/y/ayhassen/anomaly_detection/shanghaitech/testing_set/testing/merged_frames'
transform = A.Compose(
[
A.Resize(height=IMAGE_HEIGHT, width=IMAGE_WIDTH),
A.Normalize(
mean=[0.0, 0.0, 0.0],
std=[1.0, 1.0, 1.0],
max_pixel_value=255.0,
),
ToTensorV2(),
],
)
train_loader, val_loader = get_loaders(
TRAIN_DIR,
VAL_DIR,
BATCH_SIZE,
transform,
NUM_WORKERS,
PIN_MEMORY,
)
model = Conv_AE_LSTM().to(DEVICE)
if LOAD_MODEL:
load_checkpoint(torch.load("./checkpoints/modelv1.pth"), model)
mse(train_loader, model, device=DEVICE)
# save_predictions_as_imgs(
# train_loader, model, folder='./test', device=DEVICE
# )