Skip to content

Commit

Permalink
remove positive_terms parameters and clarify classes values
Browse files Browse the repository at this point in the history
  • Loading branch information
Waliens committed Jun 5, 2020
1 parent b67f5b7 commit ade33f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
17 changes: 2 additions & 15 deletions descriptor.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -93,27 +93,14 @@
{
"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,
"id": "cytomine_binary",
"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",
Expand Down
18 changes: 9 additions & 9 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ade33f0

Please sign in to comment.