From ade33f007cd9b97ae62fd9532845701db1e42c94 Mon Sep 17 00:00:00 2001 From: Waliens Date: Fri, 5 Jun 2020 14:57:38 +0200 Subject: [PATCH] remove positive_terms parameters and clarify classes values --- descriptor.json | 17 ++--------------- run.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/descriptor.json b/descriptor.json index f30376b..8fa85b3 100644 --- a/descriptor.json +++ b/descriptor.json @@ -1,5 +1,5 @@ { - "command-line": "python run.py CYTOMINE_HOST CYTOMINE_PUBLIC_KEY CYTOMINE_PRIVATE_KEY CYTOMINE_ID_PROJECT CYTOMINE_ID_SOFTWARE CYTOMINE_ID_USERS CYTOMINE_ID_IMAGES CYTOMINE_ID_TERMS CYTOMINE_POSITIVE_TERMS CYTOMINE_REVIEWED CYTOMINE_ZOOM_LEVEL CYTOMINE_BINARY PYXIT_TARGET_WIDTH PYXIT_TARGET_HEIGHT N_JOBS PYXIT_TRANSPOSE PYXIT_N_SUBWINDOWS PYXIT_INTERPOLATION PYXIT_FIXED_SIZE PYXIT_COLORSPACE PYXIT_MIN_SIZE PYXIT_MAX_SIZE FOREST_N_ESTIMATORS FOREST_MIN_SAMPLES_SPLIT FOREST_MAX_FEATURES SVM_C SEED SVM", + "command-line": "python run.py CYTOMINE_HOST CYTOMINE_PUBLIC_KEY CYTOMINE_PRIVATE_KEY CYTOMINE_ID_PROJECT CYTOMINE_ID_SOFTWARE CYTOMINE_ID_USERS CYTOMINE_ID_IMAGES CYTOMINE_ID_TERMS CYTOMINE_REVIEWED CYTOMINE_ZOOM_LEVEL CYTOMINE_BINARY PYXIT_TARGET_WIDTH PYXIT_TARGET_HEIGHT N_JOBS PYXIT_TRANSPOSE PYXIT_N_SUBWINDOWS PYXIT_INTERPOLATION PYXIT_FIXED_SIZE PYXIT_COLORSPACE PYXIT_MIN_SIZE PYXIT_MAX_SIZE FOREST_N_ESTIMATORS FOREST_MIN_SAMPLES_SPLIT FOREST_MAX_FEATURES SVM_C SEED SVM", "inputs": [ { "name": "Cytomine host", @@ -93,7 +93,7 @@ { "default-value": false, "name": "Binary classification", - "description": "Whether (true) or not (false) to treat the problem as a binary classification or not. If true cytomine_positive_terms should contain the list of terms considered as positive. Otherwise, there will be as many classes as terms.", + "description": "Whether or not to treat the problem as a binary classification or not. Annotations with terms given in cytomine_id_terms are considered foreground, all others are considered background.", "set-by-server": false, "value-key": "@ID", "optional": true, @@ -101,19 +101,6 @@ "type": "Boolean", "command-line-flag": "--@id" }, - { - "default-value": "", - "name": "Cytomine positive terms", - "description": "Contains the ids of the terms that represent the positive class.", - "set-by-server": false, - "value-key": "@ID", - "optional": true, - "id": "cytomine_positive_terms", - "type": "ListDomain", - "uri": "/api/project/$currentProject$/term.json", - "uri-print-attribute": "name", - "command-line-flag": "--@id" - }, { "default-value": 0, "name": "Cytomine reviewed", diff --git a/run.py b/run.py index 3e20206..5291e4c 100644 --- a/run.py +++ b/run.py @@ -31,27 +31,28 @@ def main(argv): # transform classes cj.job.update(progress=50, statusComment="Transform classes...") - classes = parse_domain_list(cj.parameters.cytomine_id_terms) - positive_classes = parse_domain_list(cj.parameters.cytomine_positive_terms) - classes = np.array(classes) if len(classes) > 0 else np.unique(y) - n_classes = classes.shape[0] + foreground_classes = parse_domain_list(cj.parameters.cytomine_id_terms) + foreground_classes = np.array(foreground_classes) if len(foreground_classes) > 0 else np.unique(y) + n_classes = foreground_classes.shape[0] + 1 # filter unwanted terms cj.logger.info("Size before filtering:") cj.logger.info(" - x: {}".format(x.shape)) cj.logger.info(" - y: {}".format(y.shape)) - keep = np.in1d(y, classes) + keep = np.in1d(y, foreground_classes) x, y = x[keep], y[keep] cj.logger.info("Size after filtering:") cj.logger.info(" - x: {}".format(x.shape)) cj.logger.info(" - y: {}".format(y.shape)) if cj.parameters.cytomine_binary: + # 0 (background) vs 1 (classes from cytomine_id_terms) cj.logger.info("Will be training on 2 classes ({} classes before binarization).".format(n_classes)) - y = np.in1d(y, positive_classes).astype(np.int) + y = np.ones(y.shape) else: + # 0 (background vs 1 vs 2 vs ... n (n classes from cytomine_id_terms) cj.logger.info("Will be training on {} classes.".format(n_classes)) - y = np.searchsorted(classes, y) + y = np.searchsorted(foreground_classes, y) + 1 # +1 to prevent 0 to be used as a foreground class # build model cj.job.update(progress=55, statusComment="Build model...") @@ -91,9 +92,8 @@ def main(argv): domainClassName="be.cytomine.processing.Job" ).upload() - Property(cj.job, key="classes", value=stringify(classes)).save() + Property(cj.job, key="foreground_classes", value=stringify(foreground_classes)).save() Property(cj.job, key="binary", value=cj.parameters.cytomine_binary).save() - Property(cj.job, key="positive_classes", value=stringify(positive_classes)).save() cj.job.update(status=Job.TERMINATED, status_comment="Finish", progress=100)