Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Use symlink for output_template/python/lmnet/utils/output.py #688

Merged
merged 6 commits into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions lmnet/lmnet/utils/predict_output/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import base64
import json
import os
from datetime import datetime, timezone
from datetime import datetime
from io import BytesIO

import numpy as np
import PIL.Image
import PIL.ImageDraw
from matplotlib import cm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove matplotlib from requirements.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this PR, only lmnet/networks/classification/base.py will depend on matplotlib.

from matplotlib import cm

Is it worth adding a new dependency for visualization? If not, I would remove it in another PR and reimplement this.
Related to: #485

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think it'd be nice.


from lmnet.common import Tasks
from lmnet.common import Tasks, get_color_map
from lmnet.visualize import visualize_keypoint_detection


Expand All @@ -35,12 +34,13 @@ class JsonOutput():
Please see [Output Data Specification](https://github.com/LeapMind/lmnet/wiki/Output-Data-Specification).
"""

def __init__(self, task, classes, image_size, data_format):
def __init__(self, task, classes, image_size, data_format, bench=None):
assert task in Tasks
self.task = task
self.classes = classes
self.image_size = image_size
self.data_format = data_format
self.bench = bench if bench else {}

def _classification(self, outputs, raw_images, image_files):
assert outputs.shape == (len(image_files), len(self.classes))
Expand Down Expand Up @@ -175,7 +175,7 @@ def __call__(self, outputs, raw_images, image_files):
"version": 0.2,
"task": str(self.task.value),
"classes": [{"id": i, "name": class_name} for i, class_name in enumerate(self.classes)],
"date": datetime.now(timezone.utc).isoformat(),
"date": datetime.now().isoformat(),
"results": [],
}

Expand Down Expand Up @@ -208,6 +208,7 @@ def __init__(self, task, classes, image_size):
self.task = task
self.classes = classes
self.image_size = image_size
self.color_maps = get_color_map(len(classes))

def _classification(self, result_json, raw_images, image_files):
outputs = json.loads(result_json)
Expand Down Expand Up @@ -251,13 +252,11 @@ def _semantic_segmentation(self, result_json, raw_images, image_files):
masks = np.stack(masks, axis=2)
argmax = np.argmax(masks, axis=2)

color_maps = (np.array(cm.tab20.colors) * 255).tolist()

result = []

output_image = np.zeros_like(raw_image)
for i, class_name in enumerate(self.classes):
color = color_maps[i % len(self.classes)]
color = self.color_maps[i % len(self.classes)]
output_image[argmax == i] = color

output_pil = PIL.Image.fromarray(output_image)
Expand All @@ -284,7 +283,6 @@ def _object_detection(self, result_json, raw_images, image_files):
draw = PIL.ImageDraw.Draw(image)

predictions = result["prediction"]
color_maps = (np.array(cm.tab20.colors) * 255).astype(np.uint8).tolist()

for prediction in predictions:
box = prediction["box"]
Expand All @@ -294,7 +292,7 @@ def _object_detection(self, result_json, raw_images, image_files):
class_name = prediction["class"]["name"]
score = prediction["score"]

color = tuple(color_maps[class_id % len(self.classes)])
color = tuple(self.color_maps[class_id % len(self.classes)])

draw.rectangle(xy, outline=color)
txt = "class: {:s}, score: {:.3f}".format(class_name, float(score))
Expand Down
296 changes: 0 additions & 296 deletions output_template/python/lmnet/utils/output.py

This file was deleted.

1 change: 1 addition & 0 deletions output_template/python/lmnet/utils/output.py