File crowd_counting_error_metrics.py changed (mode: 100644) (index f8d2d31..26be2d3) |
1 |
1 |
from __future__ import division |
from __future__ import division |
2 |
2 |
|
|
3 |
3 |
import torch |
import torch |
|
4 |
|
import torch.nn.functional as F |
4 |
5 |
import math |
import math |
5 |
6 |
from ignite.exceptions import NotComputableError |
from ignite.exceptions import NotComputableError |
6 |
7 |
from ignite.metrics.metric import Metric |
from ignite.metrics.metric import Metric |
|
... |
... |
class CrowdCountingMeanSSIMabs(Metric): |
129 |
130 |
# y = torch.clamp_min(y, min=0.0) |
# y = torch.clamp_min(y, min=0.0) |
130 |
131 |
y = torch.abs(y) |
y = torch.abs(y) |
131 |
132 |
y_pred = torch.abs(y_pred) |
y_pred = torch.abs(y_pred) |
|
133 |
|
print("CrowdCountingMeanSSIMabs ") |
|
134 |
|
print("y_pred", y_pred.shape) |
|
135 |
|
print("y", y.shape) |
|
136 |
|
|
132 |
137 |
|
|
133 |
138 |
ssim_metric = piq.ssim(y, y_pred) |
ssim_metric = piq.ssim(y, y_pred) |
134 |
139 |
|
|
|
... |
... |
class CrowdCountingMeanPSNRabs(Metric): |
161 |
166 |
# y = torch.clamp_min(y, min=0.0) |
# y = torch.clamp_min(y, min=0.0) |
162 |
167 |
y = torch.abs(y) |
y = torch.abs(y) |
163 |
168 |
y_pred = torch.abs(y_pred) |
y_pred = torch.abs(y_pred) |
|
169 |
|
print("CrowdCountingMeanPSNRabs ") |
|
170 |
|
print("y_pred", y_pred.shape) |
|
171 |
|
print("y", y.shape) |
|
172 |
|
|
164 |
173 |
psnr_metric = piq.psnr(y, y_pred) |
psnr_metric = piq.psnr(y, y_pred) |
165 |
174 |
|
|
166 |
175 |
|
|
167 |
176 |
|
|
|
177 |
|
|
168 |
178 |
self._sum += psnr_metric.item() * y.shape[0] |
self._sum += psnr_metric.item() * y.shape[0] |
169 |
179 |
# we multiply because ssim calculate mean of each image in batch |
# we multiply because ssim calculate mean of each image in batch |
170 |
180 |
# we multiply so we will divide correctly |
# we multiply so we will divide correctly |
|
... |
... |
class CrowdCountingMeanSSIMclamp(Metric): |
194 |
204 |
y = output[1] |
y = output[1] |
195 |
205 |
y_pred = torch.clamp_min(y_pred, min=0.0) |
y_pred = torch.clamp_min(y_pred, min=0.0) |
196 |
206 |
y = torch.clamp_min(y, min=0.0) |
y = torch.clamp_min(y, min=0.0) |
197 |
|
|
|
|
207 |
|
print("CrowdCountingMeanSSIMclamp ") |
|
208 |
|
print("y_pred", y_pred.shape) |
|
209 |
|
print("y", y.shape) |
198 |
210 |
|
|
199 |
211 |
ssim_metric = piq.ssim(y, y_pred) |
ssim_metric = piq.ssim(y, y_pred) |
200 |
212 |
|
|
|
... |
... |
class CrowdCountingMeanPSNRclamp(Metric): |
225 |
237 |
y_pred = torch.clamp_min(y_pred, min=0.0) |
y_pred = torch.clamp_min(y_pred, min=0.0) |
226 |
238 |
y = output[1] |
y = output[1] |
227 |
239 |
y = torch.clamp_min(y, min=0.0) |
y = torch.clamp_min(y, min=0.0) |
|
240 |
|
print("CrowdCountingMeanPSNRclamp ") |
|
241 |
|
print("y_pred", y_pred.shape) |
|
242 |
|
print("y", y.shape) |
|
243 |
|
|
228 |
244 |
|
|
229 |
245 |
psnr_metric = piq.psnr(y, y_pred) |
psnr_metric = piq.psnr(y, y_pred) |
230 |
246 |
|
|
File data_flow.py changed (mode: 100644) (index 764d967..74ec54c) |
... |
... |
def load_data_shanghaitech_non_overlap_test_with_densitygt(img_path, train=True, |
657 |
657 |
|
|
658 |
658 |
gt_file = h5py.File(gt_path, 'r') |
gt_file = h5py.File(gt_path, 'r') |
659 |
659 |
target = np.asarray(gt_file['density']) |
target = np.asarray(gt_file['density']) |
660 |
|
target1 = cv2.resize(target, |
|
661 |
|
(int(target.shape[1] / target_factor), int(target.shape[0] / target_factor)), |
|
662 |
|
interpolation=cv2.INTER_CUBIC) * target_factor * target_factor |
|
663 |
|
# target1 = target1.unsqueeze(0) # make dim (batch size, channel size, x, y) to make model output |
|
664 |
|
target1 = np.expand_dims(target1, |
|
|
660 |
|
# target1 = cv2.resize(target, |
|
661 |
|
# (int(target.shape[1] / target_factor), int(target.shape[0] / target_factor)), |
|
662 |
|
# interpolation=cv2.INTER_CUBIC) * target_factor * target_factor |
|
663 |
|
# # target1 = target1.unsqueeze(0) # make dim (batch size, channel size, x, y) to make model output |
|
664 |
|
target1 = np.expand_dims(target, |
665 |
665 |
axis=0) # make dim (batch size, channel size, x, y) to make model output |
axis=0) # make dim (batch size, channel size, x, y) to make model output |
666 |
666 |
return img_origin, target1 |
return img_origin, target1 |
667 |
667 |
|
|
File playground/try_to_do_overlay.py changed (mode: 100644) (index 187fcc6..61c2012) |
... |
... |
print(img_tensor.shape) |
13 |
13 |
print(density_map_tensor.shape) |
print(density_map_tensor.shape) |
14 |
14 |
print(density_map_tensor.sum()) |
print(density_map_tensor.sum()) |
15 |
15 |
density_map_tensor = torch.from_numpy(density_map_tensor).unsqueeze(dim=0).unsqueeze(dim=0) |
density_map_tensor = torch.from_numpy(density_map_tensor).unsqueeze(dim=0).unsqueeze(dim=0) |
|
16 |
|
print("density_map_tensor.shape", density_map_tensor.shape) # torch.Size([1, 1, 46, 82]) |
16 |
17 |
# module = nn.UpsamplingBilinear2d(scale_factor=8) |
# module = nn.UpsamplingBilinear2d(scale_factor=8) |
17 |
18 |
# upsampling_density_map_tensor = module(density_map_tensor) |
# upsampling_density_map_tensor = module(density_map_tensor) |
18 |
19 |
upsampling_density_map_tensor = nn.functional.interpolate(density_map_tensor, scale_factor=8)/64 |
upsampling_density_map_tensor = nn.functional.interpolate(density_map_tensor, scale_factor=8)/64 |