# Future Frame Prediction & Spatial-Temporal Dissociation
## Môi trường
Dùng docker container ncs_tungufm:
```
docker exec -ti ncs_tungufm /bin/bash
```
Thư mục chứa code bên trong container đã mount với bên ngoài:
```
cd ../andt
```
## 1. Future Frame Prediction
- Đường dẫn code trên máy 154: `/storageStudents/ncsmmlab/tungufm/Anomaly_Prediction/` (bên trong container: `/andt/Anomaly_Prediction/`)
- Lệnh train trên bộ foggy:
```
CUDA_VISIBLE_DEVICES=0 python train.py --dataset=UIT_ADrone_Foggy
```
Cờ `--dataset` là thư mục root có cấu trúc:
```
UIT_ADrone_Foggy
|__train
|____frame_foggy
|__test
|____frame_foggy
|____test_frame_mask
```
Nếu muốn train trên bộ gốc thì có thể thay đổi tại file config.py dòng 38, 39 thành frames.
```[python3]
...
def update_config(args=None, mode=None):
share_config['mode'] = mode
# assert args.dataset in ('ped2', 'avenue', 'AD_dataset_2022tech', 'AD_dataset_2022'), 'Dataset error.'
share_config['dataset'] = args.dataset
if mode == 'train':
share_config['batch_size'] = args.batch_size
share_config['train_data'] = share_config['data_root'] + args.dataset + '/train/frames_foggy'
share_config['test_data'] = share_config['data_root'] + args.dataset + '/test/frames_foggy/'
...
```
Sau khi train được:

- Checkpoint lưu ở thư mục `weights`, log lưu ở thư mục `results`.
## 2. Spatial-temporal dissociation
- Đường dẫn code trên máy 154: `/storageStudents/ncsmmlab/tungufm/VideoAnomalyDetection/` (bên trong container: `/andt/VideoAnomalyDetection/`)
- Lệnh train trên bộ UIT-ADrone foggy:
```
CUDA_VISIBLE_DEVICES=0 python script.py --dataset_path='../UIT_ADrone_Foggy/' --log_path='./log_path_adrone_foggy/'
```
- Khi muốn train trên bộ thường thì để ý file script.py dòng 29, đổi lại thành `frames`. Đối với các scene bộ Drone-Anomaly thì có thể chỉ cần để `train/`:
```[python3]
def train(args):
config.log_path = os.path.join(args.log_path, args.dataset_name)
config.dataset_path = args.dataset_path
config.dataset_name = args.dataset_name
solver = Solver(config, cluster_model=PredRes_AE_Cluster_Model, model_type=args.model_type)
train_set = ImageFolder(config.dataset_path, 'train/frames_foggy/', config.clips_length , config.frame_interval , config.img_size, config.rgb_tags)
training_loader = DataLoader(dataset=train_set, num_workers=config.batch_size, batch_size=config.batch_size, shuffle=True)
training_iter = iter(training_loader)
training_nums = len(training_loader)
```
- Sau khi train được:

- Weight sẽ lưu ở thư mục mà mình đưa vào cờ `--log_path`.
- Lệnh test lấy AUC:
```
CUDA_VISIBLE_DEVICES=0 python script.py \
--dataset_path='../UIT_ADrone_Foggy/' \
--log_path='./log_path_adrone_foggy/' \
--eval
```