-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added labelme labeler. Detection time is now calculated - for now onl…
…y in LabelMe labeler
- Loading branch information
Artur Siepietowski
committed
Oct 11, 2021
1 parent
7446501
commit 9dd6566
Showing
12 changed files
with
174 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
from typing import Type | ||
|
||
from detector.detection import PreprocessingParams, EdgeDetectorParams, SegmentDetectorParams, SegmentClustererParams, \ | ||
ClusterCleaningParams, IntersectionDetectorParams, RectangleDetectorParams | ||
from detector.utils.pvpd_base_class import PVPDBaseClass | ||
|
||
|
||
class Config(PVPDBaseClass): | ||
preprocessing_params: Type[PreprocessingParams] = None | ||
edge_detector_params: Type[EdgeDetectorParams] = None | ||
segment_detector_params: Type[SegmentDetectorParams] = None | ||
segment_clusterer_params: Type[SegmentClustererParams] = None | ||
cluster_cleaning_params: Type[ClusterCleaningParams] = None | ||
intersection_detector_params: Type[IntersectionDetectorParams] = None | ||
rectangle_detector_params: Type[RectangleDetectorParams] = None | ||
preprocessing_params: PreprocessingParams = None | ||
edge_detector_params: EdgeDetectorParams = None | ||
segment_detector_params: SegmentDetectorParams = None | ||
segment_clusterer_params: SegmentClustererParams = None | ||
cluster_cleaning_params: ClusterCleaningParams = None | ||
intersection_detector_params: IntersectionDetectorParams = None | ||
rectangle_detector_params: RectangleDetectorParams = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import base64 | ||
import json | ||
import os | ||
|
||
from labelme import LabelFile, __version__ | ||
from labelme.label_file import LabelFileError | ||
|
||
from detector.labelers.abstract import RectangleLabeler | ||
from detector.utils.utils import to_camel | ||
|
||
|
||
class LabelMeLabeler(RectangleLabeler): | ||
extension = 'json' | ||
|
||
def __save(self, filename, shapes, image_path, image_height, image_width, image_data=None, tags=None): | ||
if image_data is not None: | ||
image_data = base64.b64encode(image_data).decode("utf-8") | ||
image_height, image_width = LabelFile._check_image_height_and_width( | ||
image_data, image_height, image_width | ||
) | ||
if tags is None: | ||
tags = {} | ||
data = dict( | ||
version=__version__, | ||
flags=None, | ||
shapes=shapes, | ||
imagePath=image_path, | ||
imageData=image_data, | ||
imageHeight=image_height, | ||
imageWidth=image_width, | ||
) | ||
for key, value in tags.items(): | ||
assert key not in data | ||
data[to_camel(key)] = value | ||
try: | ||
with open(filename, "w") as f: | ||
json.dump(data, f, ensure_ascii=False, indent=2, default=str) | ||
except Exception as e: | ||
raise LabelFileError(e) | ||
|
||
@staticmethod | ||
def __create_shape(rectangle): | ||
return { | ||
"label": "0", | ||
"points": rectangle.tolist(), | ||
"group_id": None, | ||
"shape_type": "polygon", | ||
"flags": {} | ||
} | ||
|
||
def label_image(self): | ||
self.labels_collector = self.rectangles | ||
self.labeled = True | ||
return self.rectangles | ||
|
||
def create_label_file(self): | ||
if not self.labeled: | ||
self.label_image() | ||
root, ext = os.path.splitext(self.label_path) | ||
file_name = f'{root}.{self.extension}' | ||
image_data = LabelFile().load_image_file(self.image_path) | ||
shapes = [self.__create_shape(rectangle) for rectangle in self.rectangles] | ||
self.__save(file_name, shapes, f'{root}.JPG', self.preprocessed_image.shape[0], | ||
self.preprocessed_image.shape[1], image_data, self.tags) | ||
return file_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
imgviz==1.4.0 | ||
labelme==4.5.13 | ||
pandas==1.3.3 | ||
PyQt5==5.15.2 | ||
PyQt5-sip==12.9.0 | ||
pytz==2021.3 | ||
PyYAML==5.4.1 | ||
QtPy==1.11.2 | ||
Shapely==1.7.1 | ||
termcolor==1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters