File debug/verify_model_shb_best.py changed (mode: 100644) (index 120e444..a615b4e) |
... |
... |
from hard_code_variable import HardCodeVariable |
4 |
4 |
from data_util import ShanghaiTechDataPath |
from data_util import ShanghaiTechDataPath |
5 |
5 |
from visualize_util import save_img, save_density_map |
from visualize_util import save_img, save_density_map |
6 |
6 |
import os |
import os |
|
7 |
|
import numpy as np |
7 |
8 |
from data_flow import get_train_val_list, get_dataloader, create_training_image_list |
from data_flow import get_train_val_list, get_dataloader, create_training_image_list |
|
9 |
|
import cv2 |
8 |
10 |
|
|
9 |
11 |
def visualize_evaluation_shanghaitech_keepfull(model): |
def visualize_evaluation_shanghaitech_keepfull(model): |
10 |
12 |
model = model.cuda() |
model = model.cuda() |
|
... |
... |
def visualize_evaluation_shanghaitech_keepfull(model): |
29 |
31 |
save_density_map(label.numpy()[0][0], save_path) |
save_density_map(label.numpy()[0][0], save_path) |
30 |
32 |
pred = model(img.cuda()) |
pred = model(img.cuda()) |
31 |
33 |
predicted_density_map = pred.detach().cpu().clone().numpy() |
predicted_density_map = pred.detach().cpu().clone().numpy() |
32 |
|
save_density_map(predicted_density_map[0][0], save_pred_path) |
|
|
34 |
|
predicted_density_map_enlarge = cv2.resize(np.squeeze(predicted_density_map[0][0]), (int(predicted_density_map.shape[3] * 8), int(predicted_density_map.shape[2] * 8)), interpolation=cv2.INTER_CUBIC) / 64 |
|
35 |
|
save_density_map(predicted_density_map_enlarge, save_pred_path) |
33 |
36 |
print("pred " + save_pred_path + " value " + str(predicted_density_map.sum())) |
print("pred " + save_pred_path + " value " + str(predicted_density_map.sum())) |
34 |
|
|
|
35 |
|
|
|
|
37 |
|
print("cont compare " + str(predicted_density_map.sum()) + " " + str(predicted_density_map_enlarge.sum())) |
|
38 |
|
print("shape compare " + str(predicted_density_map.shape) + " " + str(predicted_density_map_enlarge.shape)) |
36 |
39 |
""" |
""" |
37 |
40 |
Document on save load model |
Document on save load model |
38 |
41 |
https://pytorch.org/tutorials/beginner/saving_loading_models.html |
https://pytorch.org/tutorials/beginner/saving_loading_models.html |