Skip to content

Commit

Permalink
Handle all zoom values (#14)
Browse files Browse the repository at this point in the history
Provide a `--zoom` argument to rescale images according to zoom.
  • Loading branch information
CloudyOverhead authored May 4, 2021
1 parent 2faf1d9 commit f20e92f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ At inference time, navigate to the directory you want to run predictions on. The
- `python -m acrosome_counter . --infer` to produce predictions. You may also add `--plot` to plot the results during execution.
- `python -m acrosome_counter . --review` to review the predictions produced previously. You may also use `python -m acrosome_counter . --infer --review` to automatically fall into review mode after inference.

You may also use `-t` or `--threshold` to filter results according to confidence. For instance, `python -m acrosome_counter . --infer --review -t 0.2` would discard all predictions with confidence under `0.2`. Threshold ranges from `0` to `1` and is `0.1` by default.

You may also use `-z` or `--zoom` if your input images have a zoom different from 20 ×. For instance, `python -m acrosome_counter . --infer --review --zoom 40` would resize images at 40 × magnification to the appropriate 20 ×.

`acrosome-counter` saves predictions as a XML file under the current directory (`.`) and statistics as a CSV file. The XML file is compatible with [CVAT](https://github.com/openvinotoolkit/cvat). The CSV file can be opened from any software that can parse tabular data, such as Microsoft Excel.


Expand Down
4 changes: 3 additions & 1 deletion acrosome_counter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from acrosome_counter.load_dataset import Dataset
from acrosome_counter.build_model import build_cfg
from acrosome_counter.train import Trainer
from acrosome_counter.predict import Predictor
from acrosome_counter.predict import Predictor, adjust_zoom


def main(args):
Expand All @@ -29,6 +29,7 @@ def main(args):
is_training, args.batch_size, args.learning_rate, args.qty_iters,
)
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = args.threshold
adjust_zoom(cfg, args.zoom)
predictor = Predictor(cfg)
predictor(dataset, plot=args.plot)
predictor.export_xml()
Expand All @@ -46,6 +47,7 @@ def main(args):
parser.add_argument('-it', '--qty_iters', default=1, type=int)
parser.add_argument('-lr', '--learning_rate', default=2.5E-4, type=float)
parser.add_argument('-t', '--threshold', default=.1, type=float)
parser.add_argument('-z', '--zoom', default=20, type=float)
parser.add_argument('--train', action='store_true')
parser.add_argument('--infer', action='store_true')
parser.add_argument('--plot', action='store_true')
Expand Down
7 changes: 7 additions & 0 deletions acrosome_counter/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

mpl.use('TkAgg')

DEFAULT_ZOOM = 20


class Predictor(DefaultPredictor):
def __init__(self, cfg):
Expand Down Expand Up @@ -102,3 +104,8 @@ def export_csv(self, dest_path=None):
class_name = MAP_NAMES[class_]
quantities.loc[filename, class_name] += 1
quantities.to_csv(dest_path, sep=';')


def adjust_zoom(cfg, target_zoom):
cfg.INPUT.MIN_SIZE_TEST *= DEFAULT_ZOOM / target_zoom
cfg.INPUT.MAX_SIZE_TEST *= DEFAULT_ZOOM / target_zoom

0 comments on commit f20e92f

Please sign in to comment.