Skip to content

Commit

Permalink
Fix(epoch_metric): fix epoch metric hand out
Browse files Browse the repository at this point in the history
  • Loading branch information
Qovaxx committed Jul 19, 2020
1 parent 2d9b9e3 commit f280edd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ pipeline:
bash ./tools/train.sh \
--config-path=./configs/default.py \
--cuda-visible-devices=0,1,2,3 \
--is-distributed=false
--is-distributed=true
8 changes: 4 additions & 4 deletions configs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
)

DATA = dict(
train=dict(type=__data_type, path=__psga_dirpath, phase="train", fold=__fold, tiles_intersection=0.5,
micron_tile_size=__microns_tile_size, crop_emptiness_degree=0.9, label_binning=True,
subsample_tiles_count=10, balance_subsample=True),
# train=dict(type=__data_type, path=__psga_dirpath, phase="train", fold=__fold, tiles_intersection=0.5,
# micron_tile_size=__microns_tile_size, crop_emptiness_degree=0.9, label_binning=True,
# subsample_tiles_count=10, balance_subsample=True),

val=dict(type=__data_type, path=__psga_dirpath, phase="val", fold=__fold, tiles_intersection=0.0,
micron_tile_size=__microns_tile_size, crop_emptiness_degree=0.95, label_binning=True),
Expand Down Expand Up @@ -96,7 +96,7 @@
train=False, unfreeze_epoch=3),
dict(type="NormalizationLockHook", train=False, requires_grad=None),

dict(type="ModifiedPytorchDPHook"),
dict(type="ModifiedPytorchDDPHook"),
# dict(type="OptimizerHook", name="base"),

dict(type="EpochMetricHook", handle=dict(qwk="qwk_metric"))
Expand Down
18 changes: 0 additions & 18 deletions scripts/dev2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ def show(image):
plt.imshow(image)
plt.show()

from collections import Counter, defaultdict
from numpy.random import choice
import random
from typing import Iterable, List

labels = [5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + [10] * 30 + [332] * 2 + [111] * 11111
# count = 20





indices = balanced_subsample(labels, 20)
print(Counter(np.array(labels)[indices]))



a = 4



Expand Down
2 changes: 1 addition & 1 deletion src/psga/data_source/provider/kaggle/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __getitem__(self, item: int) -> Dict[str, Union[torch.Tensor, np.ndarray, in
selected_indices = np.asarray(list(range(image_tiles.shape[0])))
if self._subsample_tiles_count:
if self._balance_subsample:
selected_indices = balanced_subsample(labels, count=self._subsample_tiles_count)
selected_indices = np.asarray(balanced_subsample(labels, count=self._subsample_tiles_count))
else:
selected_indices = np.random.choice(list(range(image_tiles.shape[0])),
size=self._subsample_tiles_count, replace=False)
Expand Down
9 changes: 3 additions & 6 deletions src/psga/train/contrib/hooks/epoch_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ppln.hooks.registry import HOOKS
from ppln.hooks.base import BaseHook
from ppln.hooks.priority import Priority
from ppln.utils.misc import get_dist_info

from ..utils.dist import all_gather_cpu

Expand Down Expand Up @@ -61,11 +60,9 @@ def after_epoch(self, runner: Runner) -> NoReturn:
inputs = inputs.index_select(self._inputs_dim, indices)
targets = targets.index_select(self._targets_dim, indices)

rank, _ = get_dist_info()
if rank == 0:
func_name = self._handle[metric_name]
metric = runner.batch_processor.estimate(func_name, inputs, targets)
runner.log_buffer.output[metric_name] = metric.item()
func_name = self._handle[metric_name]
metric = runner.batch_processor.estimate(func_name, inputs, targets)
runner.log_buffer.output[metric_name] = metric.item()

def _flat(self, data: List[Dict[str, torch.Tensor]], key: str, dim: int) -> torch.Tensor:
tensor = torch.cat([batch[key] for batch in data], dim=dim)
Expand Down
14 changes: 7 additions & 7 deletions src/psga/train/tile_classifier/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
decode_ordinal_targets
)
from ..utils import to_chunks
import numpy as np
import matplotlib.pyplot as plt
def show(image):
plt.figure()
image = image * np.array([32.75003156, 59.0587483, 40.4596739]) + np.array([236.71301302, 217.72548731, 229.42839042])
plt.imshow(image)
plt.show()
# import numpy as np
# import matplotlib.pyplot as plt
# def show(image):
# plt.figure()
# image = image * np.array([32.75003156, 59.0587483, 40.4596739]) + np.array([236.71301302, 217.72548731, 229.42839042])
# plt.imshow(image)
# plt.show()
# viz = np.moveaxis(batch_images.cpu().numpy(), 1, -1)


Expand Down

0 comments on commit f280edd

Please sign in to comment.