MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / print_class_histogram

Function print_class_histogram

examples/FasterRCNN/data.py:36–62  ·  view source on GitHub ↗

Args: roidbs (list[dict]): the same format as the output of `training_roidbs`.

(roidbs)

Source from the content-addressed store, hash-verified

34
35
36def print_class_histogram(roidbs):
37 """
38 Args:
39 roidbs (list[dict]): the same format as the output of `training_roidbs`.
40 """
41 class_names = DatasetRegistry.get_metadata(cfg.DATA.TRAIN[0], 'class_names')
42 # labels are in [1, NUM_CATEGORY], hence +2 for bins
43 hist_bins = np.arange(cfg.DATA.NUM_CATEGORY + 2)
44
45 # Histogram of ground-truth objects
46 gt_hist = np.zeros((cfg.DATA.NUM_CATEGORY + 1,), dtype=np.int)
47 for entry in roidbs:
48 # filter crowd?
49 gt_inds = np.where((entry["class"] > 0) & (entry["is_crowd"] == 0))[0]
50 gt_classes = entry["class"][gt_inds]
51 if len(gt_classes):
52 assert gt_classes.max() <= len(class_names) - 1
53 gt_hist += np.histogram(gt_classes, bins=hist_bins)[0]
54 data = list(itertools.chain(*[[class_names[i + 1], v] for i, v in enumerate(gt_hist[1:])]))
55 COL = min(6, len(data))
56 total_instances = sum(data[1::2])
57 data.extend([None] * ((COL - len(data) % COL) % COL))
58 data.extend(["total", total_instances])
59 data = itertools.zip_longest(*[data[i::COL] for i in range(COL)])
60 # the first line is BG
61 table = tabulate(data, headers=["class", "#box"] * (COL // 2), tablefmt="pipe", stralign="center", numalign="left")
62 logger.info("Ground-Truth category distribution:\n" + colored(table, "cyan"))
63
64
65class TrainingDataPreprocessor:

Callers 1

get_train_dataflowFunction · 0.85

Calls 2

get_metadataMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected