pyapi¶
script¶
Script¶
-
class
lost.pyapi.script.
Script
(pe_id=None)[source]¶ Superclass for a user defined Script.
Custom scripts need to inherit from Script and implement the main method.
-
pe_id
¶ Pipe element id. Assign the pe id of a pipline script in order to emulate this script in a jupyter notebook for example.
Type: int
-
create_label_tree
(name, external_id=None)[source]¶ Create a new LabelTree
Parameters: - name (str) – Name of the tree / name of the root leaf.
- external_id (str) – An external id for the root leaf.
Returns: The created LabelTree.
Return type:
-
get_abs_path
(path)[source]¶ Get absolute path in current file system.
Parameters: path (str) – A relative path. Returns: Absolute path Return type: str
-
get_alien_element
(pe_id)[source]¶ Get an pipeline element by id from somewhere in the LOST system.
It is an alien element since it is most likely not part of the pipeline instance this script belongs to.
Parameters: pe_id (int) – PipeElementID of the alien element. Returns:
-
get_arg
(arg_name)[source]¶ Get argument value by name for this script.
Parameters: arg_name (str) – Name of the argument. Returns: Value of the given argument.
-
get_label_tree
(name)[source]¶ Get a LabelTree by name.
Parameters: name (str) – Name of the desired LabelTree. - Retruns:
lost.logic.label.LabelTree
or None:- If a label tree with the given name exists it will be returned. Otherwise None will be returned
-
get_path
(file_name, context='instance', ptype='abs')[source]¶ Get path for the filename in a specific context in filesystem.
Parameters: - file_name (str) – Name or relative path for a file.
- context (str) – Options: instance, pipe, static
- ptype (str) – Type of this path. Can be relative or absolute Options: abs, rel
Returns: Path to the file in the specified context.
Return type: str
-
get_rel_path
(path)[source]¶ Get relativ path for current project
Parameters: path (str) – A absolute path Returns: Relative path Return type: str
-
instance_context
¶ Get the path to store files that are only valid for this instance.
Type: str
-
iteration
¶ Get the current iteration.
Number of times this script has been executed.
Type: int
-
logger
¶ A standard python logger for this script.
It will log to the pipline log file.
Type: logging.Logger
-
pipe_context
¶ Root path to store files that should be visible for all elements in the pipeline.
Type: str
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
progress
¶ Get current progress that is displayed in the progress bar of this script.
Current progress in percent 0…100
Type: float
-
reject_execution
()[source]¶ Reject execution of this script and set it to PENDING again.
Note
This method is useful if you want to execute this script only when some condition based on previous pipeline elements is meet.
-
report_err
(msg)[source]¶ Report an error for this user script to portal
Parameters: msg – The error message that should be reported. Note
You can call this method multiple times if you like. All messages will be concatenated an sent to the portal.
-
static_context
¶ Get the static path.
Files that are stored at this path can be accessed by all instances of a script.
Type: str
-
inout¶
ScriptOutput¶
-
class
lost.pyapi.inout.
ScriptOutput
(script)[source]¶ Special
Output
class sincelost.pyapi.script.Script
objects may manipulate and request annotations.-
add_annos
(img_path, img_labels=None, img_sim_class=None, annos=[], anno_types=[], anno_labels=[], anno_sim_classes=[], frame_n=None, video_path=None)[source]¶ Add annos in list style to an image.
Parameters: - img_path (str) – Path to the image where annotations are added for.
- img_labels (list of int) – Labels that will be assigned to the image. Each label in the list is represented by a label_leaf_id.
- img_sim_class (int) – A culster id that will be used to cluster this image in the MIA annotation tool.
- annos (list of list) – A list of POINTs: [x,y] BBOXes: [x,y,w,h] LINEs or POLYGONs: [[x,y], [x,y], …]
- anno_types (list of str) – Can be ‘point’, ‘bbox’, ‘line’, ‘polygon’
- anno_labels (list of list of int) – Labels for the twod annos.
Each label in the list is represented by a label_leaf_id.
(see also
LabelLeaf
). - anno_sim_classes (list of ints) – List of arbitrary cluster ids that are used to cluster annotations in the MIA annotation tool.
- frame_n (int) – If img_path belongs to a video frame_n indicates the framenumber.
- video_path (str) – If img_path belongs to a video this is the path to this video.
Example
Add annotations to an:
>>> self.outp.add_annos('path/to/img.jpg', ... annos = [ ... [0.1, 0.1, 0.2, 0.2], ... [0.1, 0.2], ... [[0.1, 0.3], [0.2, 0.3], [0.15, 0.1]] ... ], ... anno_types=['bbox', 'point', 'polygon'], ... anno_labels=[ ... [1], ... [1], ... [4] ... ], ... anno_sim_classes=[10, 10, 15] ... )
Note
In contrast to request_annos this method will broadcast the added annotations to all connected pipeline elements.
-
add_data_export
(file_path)[source]¶ Serve a file for download inside the web gui via a DataExport element.
Parameters: file_path (str) – Path to the file that should be provided for download.
-
add_visual_output
(img_path=None, html=None)[source]¶ Display an image and html in the web gui via a VisualOutput element.
Parameters: - img_path (str) – Path in the lost filesystem to the image to display.
- html (str) – HTML text to display.
-
anno_tasks
¶ list of
lost.pyapi.pipe_elements.AnnoTask
objects
-
bbox_annos
¶ Iterate over all bbox annotation.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
data_exports
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
datasources
¶ list of
lost.pyapi.pipe_elements.Datasource
objects
-
img_annos
¶ Iterate over all
lost.db.model.ImageAnno
objects in this Resultset.Returns: Iterator of lost.db.model.ImageAnno
objects.
-
line_annos
¶ Iterate over all line annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
mia_tasks
¶ list of
lost.pyapi.pipe_elements.MIATask
objects
-
point_annos
¶ Iterate over all point annotations.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
polygon_annos
¶ Iterate over all polygon annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
raw_files
¶ list of
lost.pyapi.pipe_elements.RawFile
objects
-
request_annos
(img_path, img_labels=None, img_sim_class=None, annos=[], anno_types=[], anno_labels=[], anno_sim_classes=[], frame_n=None, video_path=None)[source]¶ Request annotations for a subsequent annotaiton task.
Parameters: - img_path (str) – Path to the image where annotations are added for.
- img_label (list of int) – Labels that will be assigned to the image. The labels should be represented by a label_leaf_id. An image may have multiple labels.
- img_sim_class (int) – A culster id that will be used to cluster this image in the MIA annotation tool.
- annos (list of list) – A list of POINTs: [x,y] BBOXes: [x,y,w,h] LINEs or POLYGONs: [[x,y], [x,y], …]
- anno_types (list of str) – Can be ‘point’, ‘bbox’, ‘line’, ‘polygon’
- anno_labels (list of int) – Labels for the twod annos.
Each label in the list is represented by a label_leaf_id.
(see also
LabelLeaf
). - anno_sim_classes (list of ints) – List of arbitrary cluster ids that are used to cluster annotations in the MIA annotation tool.
- frame_n (int) – If img_path belongs to a video frame_n indicates the framenumber.
- video_path (str) – If img_path belongs to a video this is the path to this video.
Example
Request human annotations for an image with annotation proposals:
>>> self.outp.add_annos('path/to/img.jpg', ... annos = [ ... [0.1, 0.1, 0.2, 0.2], ... [0.1, 0.2], ... [[0.1, 0.3], [0.2, 0.3], [0.15, 0.1]] ... ], ... anno_types=['bbox', 'point', 'polygon'], ... anno_labels=[ ... [1], ... [1], ... [4] ... ], ... anno_sim_classes=[10, 10, 15] ... )
Reqest human annotations for an image without porposals:
>>> self.outp.request_annos('path/to/img.jpg')
-
request_bbox_annos
(img_path, boxes=[], labels=[], frame_n=None, video_path=None, sim_classes=[])[source]¶ Request BBox annotations for a subsequent annotaiton task.
Parameters: - img_path (str) – Path of the image.
- boxes (list) – A list of boxes [[x,y,w,h],..].
- labels (list) – A list of labels for each box.
- frame_n (int) – If img_path belongs to a video frame_n indicates the framenumber.
- video_path (str) – If img_path belongs to a video this is the path to this video.
- sim_classes (list) – [sim_class1, sim_class2,…] A list of similarity classes that is used to cluster BBoxes when using MIA for annotation.
Note
There are three cases when you request a bbox annotation.
- Case1: Annotate empty image
- You just want to get bounding boxes drawn by a human annotator for an image. -> Only set the img_path argument.
- Case2: Annotate image with a preset of boxes
- You want to get verified predicted bounding boxes by a human annotator and you have not predicted a label for the boxes. -> Set the img_path argument and boxes.
- Case3: Annotate image with a preset of boxes and labels
- You want to get predicted bounding boxes and the related predicted labels to be verified by a human annotator. -> Set the img_path and the boxes argument. For boxes you need to assign a list of box and a list of label_ids for labels. An annotation may have multiple labels. E.g. boxes =[[0.1,0.1,0.2,0.3],…], labels =[[1,5],[5],…]
Example
How to use this method in a Script:
>>> self.request_bbox_annos('path/to/img.png', ... boxes=[[0.1,0.1,0.2,0.3],[0.2,0.2,0.4,0.4]], ... labels=[[0],[1]] ... )
-
request_image_anno
(img_path, sim_class=None, labels=None, frame_n=None, video_path=None)[source]¶ Request a class label annotation for an image.
Parameters: - img_path (str) – Path to the image that should be annotated.
- sim_class (int) – A similarity class for this image. This similarity measure will be used to cluster images for MultiObjectAnnoation -> Images with the same sim_class will be presented to the annotator in one step.
- labels (list of int) – Labels that will be assigned to the image. Each label should represent a label_leaf_id.
- frame_n (int) – If img_path belongs to a video frame_n indicates the framenumber.
- video_path (str) – If img_path belongs to a video this is the path to this video.
Example
- Request image annotation::
>>> self.request_image_anno('path/to/image', sim_class=2)
-
sia_tasks
¶ list of
lost.pyapi.pipe_elements.SIATask
objects
-
to_df
()¶ Get a pandas DataFrame of all annotations related to this object.
Returns: - Column names are:
- ’img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’
Return type: pandas.DataFrame
-
to_vec
(columns='all')¶ Get a vector of all Annotations related to this object.
Parameters: columns (str or list of str) – ‘all’ OR ‘img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’ - Retruns:
- list OR list of lists: Desired columns
Example
Return just a list of 2d anno labels:
>>> img_anno.to_vec('anno.lbl.name') ['Aeroplane', 'Bicycle', 'Bottle', 'Horse']
Return a list of lists:
>>> self.inp.get_anno_vec.(['img.img_path', 'anno.lbl.name', ... 'anno.data', 'anno.dtype']) [ ['path/to/img1.jpg', 'Aeroplane', [0.1, 0.1, 0.2, 0.2], 'bbox'], ['path/to/img1.jpg', 'Bicycle', [0.1, 0.1], 'point'], ['path/to/img2.jpg', 'Bottle', [[0.1, 0.1], [0.2, 0.2]], 'line'], ['path/to/img3.jpg', 'Horse', [0.2, 0.15, 0.3, 0.18], 'bbox'] ]
-
twod_annos
¶ Iterate over 2D-annotations.
Returns: of lost.db.model.TwoDAnno
objects.Return type: Iterator
-
visual_outputs
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
Output¶
-
class
lost.pyapi.inout.
Output
(element)[source]¶ -
anno_tasks
¶ list of
lost.pyapi.pipe_elements.AnnoTask
objects
-
bbox_annos
¶ Iterate over all bbox annotation.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
data_exports
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
datasources
¶ list of
lost.pyapi.pipe_elements.Datasource
objects
-
img_annos
¶ Iterate over all
lost.db.model.ImageAnno
objects in this Resultset.Returns: Iterator of lost.db.model.ImageAnno
objects.
-
line_annos
¶ Iterate over all line annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
mia_tasks
¶ list of
lost.pyapi.pipe_elements.MIATask
objects
-
point_annos
¶ Iterate over all point annotations.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
polygon_annos
¶ Iterate over all polygon annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
raw_files
¶ list of
lost.pyapi.pipe_elements.RawFile
objects
-
sia_tasks
¶ list of
lost.pyapi.pipe_elements.SIATask
objects
-
to_df
()¶ Get a pandas DataFrame of all annotations related to this object.
Returns: - Column names are:
- ’img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’
Return type: pandas.DataFrame
-
to_vec
(columns='all')¶ Get a vector of all Annotations related to this object.
Parameters: columns (str or list of str) – ‘all’ OR ‘img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’ - Retruns:
- list OR list of lists: Desired columns
Example
Return just a list of 2d anno labels:
>>> img_anno.to_vec('anno.lbl.name') ['Aeroplane', 'Bicycle', 'Bottle', 'Horse']
Return a list of lists:
>>> self.inp.get_anno_vec.(['img.img_path', 'anno.lbl.name', ... 'anno.data', 'anno.dtype']) [ ['path/to/img1.jpg', 'Aeroplane', [0.1, 0.1, 0.2, 0.2], 'bbox'], ['path/to/img1.jpg', 'Bicycle', [0.1, 0.1], 'point'], ['path/to/img2.jpg', 'Bottle', [[0.1, 0.1], [0.2, 0.2]], 'line'], ['path/to/img3.jpg', 'Horse', [0.2, 0.15, 0.3, 0.18], 'bbox'] ]
-
twod_annos
¶ Iterate over 2D-annotations.
Returns: of lost.db.model.TwoDAnno
objects.Return type: Iterator
-
visual_outputs
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
Input¶
-
class
lost.pyapi.inout.
Input
(element)[source]¶ Class that represants an input of a pipeline element.
Parameters: element (object) – Related lost.db.model.PipeElement
object.-
anno_tasks
¶ list of
lost.pyapi.pipe_elements.AnnoTask
objects
-
bbox_annos
¶ Iterate over all bbox annotation.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
data_exports
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
datasources
¶ list of
lost.pyapi.pipe_elements.Datasource
objects
-
img_annos
¶ Iterate over all
lost.db.model.ImageAnno
objects in this Resultset.Returns: Iterator of lost.db.model.ImageAnno
objects.
-
line_annos
¶ Iterate over all line annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
mia_tasks
¶ list of
lost.pyapi.pipe_elements.MIATask
objects
-
point_annos
¶ Iterate over all point annotations.
Returns: Iterator of lost.db.model.TwoDAnno
.
-
polygon_annos
¶ Iterate over all polygon annotations.
Returns: Iterator of lost.db.model.TwoDAnno
objects.
-
raw_files
¶ list of
lost.pyapi.pipe_elements.RawFile
objects
-
sia_tasks
¶ list of
lost.pyapi.pipe_elements.SIATask
objects
-
to_df
()[source]¶ Get a pandas DataFrame of all annotations related to this object.
Returns: - Column names are:
- ’img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’
Return type: pandas.DataFrame
-
to_vec
(columns='all')[source]¶ Get a vector of all Annotations related to this object.
Parameters: columns (str or list of str) – ‘all’ OR ‘img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.group_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.group_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’ - Retruns:
- list OR list of lists: Desired columns
Example
Return just a list of 2d anno labels:
>>> img_anno.to_vec('anno.lbl.name') ['Aeroplane', 'Bicycle', 'Bottle', 'Horse']
Return a list of lists:
>>> self.inp.get_anno_vec.(['img.img_path', 'anno.lbl.name', ... 'anno.data', 'anno.dtype']) [ ['path/to/img1.jpg', 'Aeroplane', [0.1, 0.1, 0.2, 0.2], 'bbox'], ['path/to/img1.jpg', 'Bicycle', [0.1, 0.1], 'point'], ['path/to/img2.jpg', 'Bottle', [[0.1, 0.1], [0.2, 0.2]], 'line'], ['path/to/img3.jpg', 'Horse', [0.2, 0.15, 0.3, 0.18], 'bbox'] ]
-
twod_annos
¶ Iterate over 2D-annotations.
Returns: of lost.db.model.TwoDAnno
objects.Return type: Iterator
-
visual_outputs
¶ list of
lost.pyapi.pipe_elements.VisualOutput
objects.
-
pipeline¶
PipeInfo¶
-
class
lost.pyapi.pipeline.
PipeInfo
(pipe, dbm)[source]¶ -
description
¶ Description that was defined when pipeline was started.
Type: str
-
logfile_path
¶ Path to pipeline log file.
Type: str
-
name
¶ Name of this pipeline
Type: str
-
timestamp
¶ Timestamp when pipeline was started.
Type: str
-
timestamp_finished
¶ Timestamp when pipeline was finished.
Type: str
-
pipe_elements¶
Datasource¶
-
class
lost.pyapi.pipe_elements.
Datasource
(pe, dbm)[source]¶ -
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
path
¶ Absolute path to file or folder
Type: str
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
RawFile¶
-
class
lost.pyapi.pipe_elements.
RawFile
(pe, dbm)[source]¶ -
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
path
¶ Absolute path to file or folder
Type: str
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
AnnoTask¶
-
class
lost.pyapi.pipe_elements.
AnnoTask
(pe, dbm)[source]¶ -
configuration
¶ Configuration of this annotask.
Type: str
-
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
instructions
¶ Instructions for the annotator of this AnnoTask.
Type: str
-
name
¶ A name for this annotask.
Type: str
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
possible_label_df
¶ Get all possible labels for this annotation task in DataFrame format
- pd.DataFrame: Column names are:
- ‘idx’, ‘name’, ‘abbreviation’, ‘description’, ‘timestamp’, ‘external_id’, ‘is_deleted’, ‘parent_leaf_id’ ,’is_root’
Type: pd.DataFrame
-
progress
¶ Progress in percent.
Value range 0…100.
Type: float
-
MIATask¶
-
class
lost.pyapi.pipe_elements.
MIATask
(pe, dbm)[source]¶ -
configuration
¶ Configuration of this annotask.
Type: str
-
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
instructions
¶ Instructions for the annotator of this AnnoTask.
Type: str
-
name
¶ A name for this annotask.
Type: str
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
possible_label_df
¶ Get all possible labels for this annotation task in DataFrame format
- pd.DataFrame: Column names are:
- ‘idx’, ‘name’, ‘abbreviation’, ‘description’, ‘timestamp’, ‘external_id’, ‘is_deleted’, ‘parent_leaf_id’ ,’is_root’
Type: pd.DataFrame
-
progress
¶ Progress in percent.
Value range 0…100.
Type: float
-
SIATask¶
-
class
lost.pyapi.pipe_elements.
SIATask
(pe, dbm)[source]¶ -
configuration
¶ Configuration of this annotask.
Type: str
-
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
instructions
¶ Instructions for the annotator of this AnnoTask.
Type: str
-
name
¶ A name for this annotask.
Type: str
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
possible_label_df
¶ Get all possible labels for this annotation task in DataFrame format
- pd.DataFrame: Column names are:
- ‘idx’, ‘name’, ‘abbreviation’, ‘description’, ‘timestamp’, ‘external_id’, ‘is_deleted’, ‘parent_leaf_id’ ,’is_root’
Type: pd.DataFrame
-
progress
¶ Progress in percent.
Value range 0…100.
Type: float
-
DataExport¶
-
class
lost.pyapi.pipe_elements.
DataExport
(pe, dbm)[source]¶ -
file_path
¶ A list of absolute path to exported files
Type: list of str
-
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
VisualOutput¶
-
class
lost.pyapi.pipe_elements.
VisualOutput
(pe, dbm)[source]¶ -
html_strings
¶ list of html strings.
Type: list of str
-
img_paths
¶ List of absolute paths to images.
Type: list of str
-
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
Loop¶
-
class
lost.pyapi.pipe_elements.
Loop
(pe, dbm)[source]¶ -
inp
¶ Input of this pipeline element
Type: lost.pyapi.inout.Input
-
is_broken
¶ True if loop is broken
Type: bool
-
iteration
¶ Current iteration of this loop.
Type: int
-
max_iteration
¶ Maximum number of iteration.
Type: int
-
outp
¶ Output of this pipeline element
Type: lost.pyapi.inout.Output
-
pe_jump
¶ PipelineElement where this loop will jump to when looping.
-
pipe_info
¶ An object with pipeline informations
Type: lost.pyapi.pipeline.PipeInfo
-
model¶
ImageAnno¶
-
class
lost.db.model.
ImageAnno
(anno_task_id=None, user_id=None, timestamp=None, state=None, sim_class=None, result_id=None, img_path=None, frame_n=None, video_path=None, iteration=0, anno_time=None, is_junk=None, description=None)[source]¶ An ImageAnno represents an image annotation.
Multiple labels as well as 2d annotations (e.g. points, lines, boxes, polygons) can be assigned to an image.
-
img_path
¶ Path to the image where this anno belongs to.
Type: str
-
frame_n
¶ If this image is part of an video, frame_n indicates the frame number.
Type: int
-
video_path
¶ If this image is part of an video, this should be the path to that video in file system.
Type: str
-
sim_class
¶ The similarity class this anno belong to. It is used to cluster similar annos in MIA
Type: int
-
anno_time
¶ Overall annotation time in seconds.
-
timestamp
¶ Timestamp of ImageAnno
Type: DateTime
-
iteration
¶ The iteration of a loop when this anno was created.
Type: int
-
idx
¶ ID of this ImageAnno in database
Type: int
-
anno_task_id
¶ ID of the anno_task this ImageAnno belongs to.
Type: int
-
state
¶ See
lost.db.state.Anno
Type: enum
-
result_id
¶ Id of the related result.
-
user_id
¶ Id of the annotator.
Type: int
-
is_junk
¶ This image was marked as Junk.
Type: bool
-
description
¶ Description for this annotation. Assigned by an annotator or algorithm.
Type: str
-
get_anno_vec
(anno_type='bbox')[source]¶ Get related 2d annotations in list style.
Parameters: anno_type (str) – Can be ‘bbox’, ‘point’, ‘line’, ‘polygon’ Returns: - For POINTs:
- [[x, y], [x, y], …]
- For BBOXs:
- [[x, y, w, h], [x, y, w, h], …]
- For LINEs and POLYGONs:
- [[[x, y], [x, y],…], [[x, y], [x, y],…]]
Return type: list of list of floats Example
In the following example all bounding boxes of the image annotation will be returned in list style:
>>> img_anno.anno_vec() [[0.1 , 0.2 , 0.3 , 0.18], [0.25, 0.25, 0.2, 0.4]] >>> img_anno.get_anno_lbl_vec('name', 'bbox') #Get related label names [['cow'], ['horse']]
-
iter_annos
(anno_type='bbox')[source]¶ Iterator for all related 2D annotations of this image.
Parameters: anno_type (str) – Can be bbox’, ‘point’, ‘line’, ‘polygon’, ‘all’ - Retruns:
- iterator of
TwoDAnno
objects
Example
>>> for bb in img_anno.iter_annos('bbox'): ... do_something(bb)
-
to_df
()[source]¶ Tranform this ImageAnnotation and all related TwoDAnnotaitons into a pandas DataFrame.
Returns: - Column names are:
- ’img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.user_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘img.is_junk’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.user_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’
Return type: pandas.DataFrame
-
to_dict
(style='flat')[source]¶ Transform this ImageAnno and all related TwoDAnnos into a dict.
Parameters: style (str) – ‘flat’ or ‘hierarchical’. Return a dict in flat or nested style. Returns: In ‘flat’ style return a list of dicts with one dict per annotation. In ‘hierarchical’ style, return a nested dictionary. Return type: list of dict OR dict Note
In ‘flat’ style annotation data and lists of labels are serialized as json strings. You may want to deserialize them with json.loads()
Example
HowTo iterate through all TwoDAnnotations of this ImageAnno dictionary in flat style:
>>> for d in img_anno.to_dict(): ... print(d['img.img_path'], d['anno.lbl.name'], d['anno.dtype']) path/to/img1.jpg ['Aeroplane'] bbox path/to/img1.jpg ['Bicycle'] point
Possible keys in flat style:
>>> img_anno.to_dict()[0].keys() dict_keys([ 'img.idx', 'img.anno_task_id', 'img.timestamp', 'img.timestamp_lock', 'img.state', 'img.sim_class', 'img.frame_n', 'img.video_path', 'img.img_path', 'img.result_id', 'img.iteration', 'img.user_id', 'img.anno_time', 'img.lbl.idx', 'img.lbl.name', 'img.lbl.external_id', 'img.annotator', 'img.is_junk' 'anno.idx', 'anno.anno_task_id', 'anno.timestamp', 'anno.timestamp_lock', 'anno.state', 'anno.track_n', 'anno.dtype', 'anno.sim_class', 'anno.iteration', 'anno.user_id', 'anno.img_anno_id', 'anno.annotator', 'anno.confidence', 'anno.anno_time', 'anno.lbl.idx', 'anno.lbl.name', 'anno.lbl.external_id', 'anno.data' ])
HowTo iterate through all TwoDAnnotations of this ImageAnno dictionary in hierarchical style:
>>> h_dict = img_anno.to_dict(style='hierarchical') >>> for d in h_dict['img.twod_annos']: ... print(h_dict['img.img_path'], d['anno.lbl.name'], d['anno.dtype']) path/to/img1.jpg [Aeroplane] bbox path/to/img1.jpg [Bicycle] point
Possible keys in hierarchical style:
>>> h_dict = img_anno.to_dict(style='hierarchical') >>> h_dict.keys() dict_keys([ 'img.idx', 'img.anno_task_id', 'img.timestamp', 'img.timestamp_lock', 'img.state', 'img.sim_class', 'img.frame_n', 'img.video_path', 'img.img_path', 'img.result_id', 'img.iteration', 'img.user_id', 'img.anno_time', 'img.lbl.idx', 'img.lbl.name', 'img.lbl.external_id', 'img.annotator', 'img.twod_annos' ]) >>> h_dict['img.twod_annos'][0].keys() dict_keys([ 'anno.idx', 'anno.anno_task_id', 'anno.timestamp', 'anno.timestamp_lock', 'anno.state', 'anno.track_n', 'anno.dtype', 'anno.sim_class', 'anno.iteration', 'anno.user_id', 'anno.img_anno_id', 'anno.annotator', 'anno.confidence', 'anno.anno_time', 'anno.lbl.idx', 'anno.lbl.name', 'anno.lbl.external_id', 'anno.data' ])
-
to_vec
(columns='all')[source]¶ Transform this ImageAnnotation and all related TwoDAnnotations in list style.
Parameters: columns (str or list of str) – ‘all’ OR ‘img.idx’, ‘img.anno_task_id’, ‘img.timestamp’, ‘img.timestamp_lock’, ‘img.state’, ‘img.sim_class’, ‘img.frame_n’, ‘img.video_path’, ‘img.img_path’, ‘img.result_id’, ‘img.iteration’, ‘img.user_id’, ‘img.anno_time’, ‘img.lbl.idx’, ‘img.lbl.name’, ‘img.lbl.external_id’, ‘img.annotator’, ‘img.is_junk’, ‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_n’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.user_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’ - Retruns:
- list OR list of lists: Desired columns
Example
Return just a list of serialized 2d anno labels:
>>> img_anno.to_vec('anno.lbl.name') ["['Aeroplane']", "['Bicycle']"]
Return a list of lists:
>>> img_anno.to_vec(['img.img_path', 'anno.lbl.name', ... 'anno.lbl.idx', 'anno.dtype']) [ ['path/to/img1.jpg', "['Aeroplane']", "[14]", 'bbox'], ['path/to/img1.jpg', "['Bicycle']", "[15]", 'point'] ]
-
TwoDAnno¶
-
class
lost.db.model.
TwoDAnno
(anno_task_id=None, user_id=None, timestamp=None, state=None, track_id=None, sim_class=None, img_anno_id=None, timestamp_lock=None, iteration=0, data=None, dtype=None, confidence=None, anno_time=None, description=None)[source]¶ A TwoDAnno represents a 2D annotation/ drawing for an image.
A TwoDAnno can be of type point, line, bbox or polygon.
-
idx
¶ ID of this TwoDAnno in database
Type: int
-
anno_task_id
¶ ID of the anno_task this TwoDAnno belongs to.
Type: int
-
timestamp
¶ Timestamp created of TwoDAnno
Type: DateTime
-
timestamp_lock
¶ Timestamp locked in view
Type: DateTime
-
state
¶ can be unlocked, locked, locked_priority or labeled (see
lost.db.state.Anno
)Type: enum
-
track_id
¶ The track id this TwoDAnno belongs to.
Type: int
-
sim_class
¶ The similarity class this anno belong to. It is used to cluster similar annos in MIA.
Type: int
-
iteration
¶ The iteration of a loop when this anno was created.
Type: int
-
user_id
¶ Id of the annotator.
Type: int
-
img_anno_id
¶ ID of ImageAnno this TwoDAnno is appended to
Type: int
-
data
¶ drawing data (for e.g. x,y, width, height) of anno - depends on dtype
Type: Text
-
dtype
¶ type of TwoDAnno (for e.g. bbox, polygon) (see
lost.db.dtype.TwoDAnno
)Type: int
-
confidence
¶ Confidence of Annotation.
Type: float
-
anno_time
¶ Overall Annotation Time in ms.
-
description
¶ Description for this annotation. Assigned by an annotator or algorithm.
Type: str
-
add_label
(label_leaf_id)[source]¶ Add a label to this 2D annotation.
Parameters: label_leaf_id (int) – Id of the label_leaf that should be added.
-
bbox
¶ BBOX annotation in list style [x, y, w, h]
Example
>>> anno = TwoDAnno() >>> anno.bbox = [0.1, 0.1, 0.2, 0.2] >>> anno.bbox [0.1, 0.1, 0.2, 0.2]
Type: list
-
get_anno_vec
()[source]¶ Get annotation data in list style.
Returns: - For a POINT:
- [x, y]
- For a BBOX:
- [x, y, w, h]
- For a LINE and POLYGONS:
- [[x, y], [x, y],…]
Return type: list of floats Example
HowTo get a numpy array? In the following example a bounding box is returned:
>>> np.array(twod_anno.get_anno_vec()) array([0.1 , 0.2 , 0.3 , 0.18])
-
line
¶ LINE annotation in list style [[x, y], [x, y], …]
Example
>>> anno = TwoDAnno() >>> anno.line = [[0.1, 0.1], [0.2, 0.2]] >>> anno.line [[0.1, 0.1], [0.2, 0.2]]
Type: list of list
-
point
¶ POINT annotation in list style [x, y]
Example
>>> anno = TwoDAnno() >>> anno.point = [0.1, 0.1] >>> anno.point [0.1, 0.1]
Type: list
-
polygon
¶ polygon annotation in list style [[x, y], [x, y], …]
Example
>>> anno = TwoDAnno() >>> anno.polygon = [[0.1, 0.1], [0.2, 0.1], [0.15, 0.2]] >>> anno.polygon [[0.1, 0.1], [0.2, 0.1], [0.15, 0.2]]
Type: list of list
-
to_df
()[source]¶ Transform this annotation into a pandas DataFrame
Returns: A DataFrame where column names correspond to the keys of the dictionary returned from to_dict() method. Return type: pandas.DataFrame Note
- Column names are:
- [‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_id’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.user_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’]
-
to_dict
(style='flat')[source]¶ Transform this object into a dict.
Parameters: style (str) – ‘flat’ or ‘hierarchical’ ‘flat’: Return a dictionray in table style ‘hierarchical’: Return a nested dictionary - Retruns:
- dict: In flat or hierarchical style.
Example
Get a dict in flat style. Note that ‘anno.data’, ‘anno.lbl.idx’, ‘anno.lbl.name’ and ‘anno.lbl.external_id’ are json strings in contrast to the hierarchical style.
>>> bbox.to_dict(style='flat') { 'anno.idx': 88, 'anno.anno_task_id': None, 'anno.timestamp': None, 'anno.timestamp_lock': None, 'anno.state': None, 'anno.track_id': None, 'anno.dtype': 'bbox', 'anno.sim_class': None, 'anno.iteration': 0, 'anno.user_id': 47, 'anno.img_anno_id': None, 'anno.annotator': 'test', 'anno.confidence': None, 'anno.anno_time': None, 'anno.lbl.idx': '["14"]', 'anno.lbl.name': '["Aeroplane"]', 'anno.lbl.external_id': '["6"]', 'anno.data': '{"x": 0.1, "y": 0.1, "w": 0.2, "h": 0.2}' }
Get a dict in hierarchical style. Note that ‘anno.data’ is a dict in contrast to the flat style.
>>> bbox.to_dict(style='hierarchical') { 'anno.idx': 86, 'anno.anno_task_id': None, 'anno.timestamp': None, 'anno.timestamp_lock': None, 'anno.state': None, 'anno.track_id': None, 'anno.dtype': 'bbox', 'anno.sim_class': None, 'anno.iteration': 0, 'anno.user_id': 46, 'anno.img_anno_id': None, 'anno.annotator': 'test', 'anno.confidence': None, 'anno.anno_time': None, 'anno.lbl.idx': [14], 'anno.lbl.name': ['Aeroplane'], 'anno.lbl.external_id': ['6'], 'anno.data': { 'x': 0.1, 'y': 0.1, 'w': 0.2, 'h': 0.2 } }
-
to_vec
(columns='all')[source]¶ Tansfrom this annotation in list style.
Parameters: columns (list of str OR str) – Possible column names are: ‘all’ OR [‘anno.idx’, ‘anno.anno_task_id’, ‘anno.timestamp’, ‘anno.timestamp_lock’, ‘anno.state’, ‘anno.track_id’, ‘anno.dtype’, ‘anno.sim_class’, ‘anno.iteration’, ‘anno.user_id’, ‘anno.img_anno_id’, ‘anno.annotator’, ‘anno.confidence’, ‘anno.anno_time’, ‘anno.lbl.idx’, ‘anno.lbl.name’, ‘anno.lbl.external_id’, ‘anno.data’] Returns: A list of the desired columns. Return type: list of objects Example
If you want to get only the annotation in list style e.g. [x, y, w, h] (if this TwoDAnnotation is a bbox).
>>> anno.to_vec('anno.data') [0.1, 0.1, 0.2, 0.2]
If you want in addition also the corresponding label names and label ids for this annotation then just add additional column names:
>>> bbox.to_vec(['anno.data', 'anno.lbl.idx', 'anno.lbl.name']) [[0.1, 0.1, 0.2, 0.2], "[14]", "['Aeroplane']"]
-
LabelLeaf¶
-
class
lost.db.model.
LabelLeaf
(idx=None, name=None, abbreviation=None, description=None, timestamp=None, external_id=None, label_tree_id=None, is_deleted=None, parent_leaf_id=None, is_root=None)[source]¶ A LabelLeaf
-
idx
¶ ID in database.
Type: int
-
name
¶ Name of the LabelName.
Type: str
-
abbreviation
¶ Type: str
-
description
¶ Type: str
-
timestamp
¶ Type: DateTime
-
external_id
¶ Id of an external semantic label system (for e.g. synsetid of wordnet)
Type: str
-
is_deleted
¶ Type: Boolean
-
is_root
¶ Indicates if this leaf is the root of a tree.
Type: Boolean
-
parent_leaf_id
¶ Reference to parent LabelLeaf.
Type: Integer
-
Label¶
-
class
lost.db.model.
Label
(idx=None, dtype=None, label_leaf_id=None, img_anno_id=None, two_d_anno_id=None, annotator_id=None, timestamp_lock=None, timestamp=None, confidence=None, anno_time=None)[source]¶ Represants an Label that is related to an annoation.
-
idx
¶ ID in database.
Type: int
-
dtype
¶ lost.db.dtype.Result
type of this attribute.Type: enum
-
label_leaf_id
¶ ID of related
model.LabelLeaf
.
-
img_anno_id
¶ Type: int
-
two_d_anno_id
¶ Type: int
-
timestamp
¶ Type: DateTime
-
timestamp_lock
¶ Type: DateTime
-
label_leaf
¶ related
model.LabelLeaf
object.Type: model.LabelLeaf
-
annotator_id
¶ GroupID of Annotator who has assigned this Label.
Type: Integer
-
confidence
¶ Confidence of Annotation.
Type: float
-
anno_time
¶ Time of annotaiton duration
Type: float
-
logic.label¶
LabelTree¶
-
class
lost.logic.label.
LabelTree
(dbm, root_id=None, root_leaf=None, name=None, logger=None)[source]¶ A class that represants a LabelTree.
Parameters: - dbm (
lost.db.access.DBMan
) – Database manager object. - root_id (int) – label_leaf_id of the root Leaf.
- root_leaf (
lost.db.model.LabelLeaf
) – Root leaf of the tree. - name (str) – Name of a label tree.
- logger (logger) – A logger.
-
create_child
(parent_id, name, external_id=None)[source]¶ Create a new leaf in label tree.
Parameters: - parent_id (int) – Id of the parend leaf.
- name (str) – Name of the leaf e.g the class name.
- external_id (str) – Some id of an external label system.
- Retruns:
lost.db.model.LabelLeaf
: The the created child leaf.
-
create_root
(name, external_id=None)[source]¶ Create the root of a label tree.
Parameters: - name (str) – Name of the root leaf.
- external_id (str) – Some id of an external label system.
- Retruns:
lost.db.model.LabelLeaf
or None:- The created root leaf or None if a root leaf with same name is already present in database.
-
delete_subtree
(leaf)[source]¶ Recursive delete all leafs in subtree starting with leaf
Parameters: leaf ( lost.db.model.LabelLeaf
) – Delete all childs of this leaf. The leaf itself stays.
-
get_child_vec
(parent_id, columns='idx')[source]¶ Get a vector of child labels.
Parameters: - parent_id (int) – Id of the parent leaf.
- columns (str or list of str) – Can be any attribute of
lost.db.model.LabelLeaf
for example ‘idx’, ‘external_idx’, ‘name’ or a list of these e.g. [‘name’, ‘idx’]
Example
>>> label_tree.get_child_vec(1, columns='idx') [2, 3, 4]
>>> label_tree.get_child_vec(1, columns=['idx', 'name']) [ [2, 'cow'], [3, 'horse'], [4, 'person'] ]
Returns: Return type: list in the requested columns
-
import_df
(df)[source]¶ Import LabelTree from DataFrame
Parameters: df (pandas.DataFrame) – LabelTree in DataFrame style. - Retruns:
lost.db.model.LabelLeaf
or None:- The created root leaf or None if a root leaf with same name is already present in database.
- dbm (
dtype¶
util methods¶
anno_helper¶
A module with helper methods to tranform annotations into different formats and to crop annotations from an image.
-
lost.pyapi.utils.anno_helper.
calc_box_for_anno
(annos, types, point_padding=0.05)[source]¶ Calculate a bouning box for an arbitrary 2DAnnotation.
Parameters: - annos (list) – List of annotations.
- types (list) – List of types.
- point_padding (float, optional) – In case of a point we need to add some padding to get a box.
Returns: A list of bounding boxes in format [[xc,yc,w,h],…]
Return type: list
-
lost.pyapi.utils.anno_helper.
crop_boxes
(annos, types, img, context=0.0, draw_annotations=False)[source]¶ Crop a bounding boxes for TwoDAnnos from image.
Parameters: - annos (list) – List of annotations.
- types (list) – List of types.
- img (numpy.array) – The image where boxes should be cropped from.
- context (float) – The context that should be added to the box.
- draw_annotations (bool) – If true, annotation will be painted inside the crop.
Returns: A tuple that contains a list of image crops and a list of bboxes [[xc,yc,w,h],…]
Return type: (list of numpy.array, list of list of float)
-
lost.pyapi.utils.anno_helper.
divide_into_patches
(img, x_splits=2, y_splits=2)[source]¶ Divide image into x_splits*y_splits patches.
Parameters: - img (array) – RGB image (skimage.io.imread).
- x_splits (int) – Number of elements on x axis.
- y_splits (int) – Number of elements on y axis.
Returns: - img_patches, box_coordinates
img batches and box coordinates of these patches in the image.
Return type: list, list
Note
- img_patches are in following order:
- [[x0,y0], [x0,y1],…[x0,yn],…,[xn,y0], [xn, y1]…[xn,yn]]
-
lost.pyapi.utils.anno_helper.
draw_annos
(annos, types, img, color=(255, 0, 0), point_r=2)[source]¶ Draw annotations inside a image
Parameters: - annos (list) – List of annotations.
- types (list) – List of types.
- img (numpy.array) – The image to draw annotations in.
- color (tuple) – (R,G,B) color that is used for drawing.
Note
The given image will be directly edited!
Returns: Image with drawn annotations Return type: numpy.array
-
lost.pyapi.utils.anno_helper.
to_abs
(annos, types, img_size)[source]¶ Convert relative annotation coordinates to absolute ones
Parameters: - annos (list of list) –
- types (list of str) –
- img_size (tuple) – (width, height) of the image in pixels.
Returns: Annotations in absolute format.
Return type: list of list
-
lost.pyapi.utils.anno_helper.
trans_boxes_to
(boxes, convert_to='minmax')[source]¶ Transform a box from standard lost format into a different format
Parameters: - boxes (list of list) – Boxes in standard lost format [[xc,yc,w,h],…]
- convert_to (str) – minmax -> [[xmim,ymin,xmax,ymax]…]
Returns: Converted boxes.
Return type: list of list
blacklist¶
A helper module to deal with blacklists.
-
class
lost.pyapi.utils.blacklist.
ImgBlacklist
(my_script, name='img-blacklist.json', context='pipe')[source]¶ A class to deal with image blacklists.
Such blacklists are often used for annotation loops, in order to prevent annotating the same image multiple times.
-
my_script
¶ The script instance that creates this blacklist.
Type: lost.pyapi.script.Script
-
name
¶ The name of the blacklist file.
Type: str
-
context
¶ Options: instance, pipe, static
Type: str
Example
Add images to blacklist.
>>> blacklist = ImgBlacklist(self, name='blacklist.json') >>> blacklist.add(['path/to/img0.jpg']) >>> balcklist.save()
Load a blacklist and check if a certain image is already in list.
>>> blacklist = ImgBlacklist(self, name='blacklist.json') >>> blacklist.contains('path/to/img0.jpg') True >>> blacklist.contains('path/to/img1.jpg') False
Get list of images that are not part of the blacklist
>>> blacklist.get_whitelist(['path/to/img0.jpg', 'path/to/img1.jpg', 'path/to/img2.jpg']) ['path/to/img1.jpg', 'path/to/img2.jpg']
Add images to the blacklist
>>> blacklist.add(['path/to/img1.jpg', 'path/to/img2.jpg'])
-
add
(imgs)[source]¶ Add a list of images to blacklist.
Parameters: imgs (list) – A list of image identifiers that should be added to the blacklist.
-
contains
(img)[source]¶ Check if blacklist contains a spcific image
Parameters: img (str) – The image identifier Returns: True if img in blacklist, False if not. Return type: bool
-
get_whitelist
(img_list, n='all')[source]¶ Get a list of images that are not part of the blacklist.
Parameters: - img_list (list of str) – A list of images where should be checked if they are in the blacklist
- n ('all' or 'int') – The maximum number of images that should be returned.
Returns: A list of images that are not in the blacklist.
Return type: list of str
-
vis¶
-
lost.pyapi.utils.vis.
boxes
(script, img_anno, figsize=(15, 15), fontsize=15, label_offset=(0, 15))[source]¶ Draw bboxes on into an matplotlib figures
Parameters: - script (lost.pyapi.script.Script) – The script object that uses this method.
- img_anno (lost.pyapi.annos.ImageAnno) – The image anno where bboxes should be visualized for.
- figsize (tuple) – Size of the matplotlib figure
- fontsize (ing) – Fontsize in pixels for label display
- label_offset (tuple) – Position of the label in pixels in relation to the upper left corner of the box.
Returns: Matplotlib figure
-
lost.pyapi.utils.vis.
vis_tracks
(img, tracks, frame_n, dots=15, figsize=(10, 10), dot_radius=5, linewidth=2)[source]¶ Visualize a track on image
Parameters: - img (array or str) – An RGB image or path to the image file.
- tracks (array) – [[frame_n, track_id, xc, yc, w, h]…[…]] Box is defined relative to the image.
- frame_n (int) – The frame number belonning to the image
- dots (int) – Number of dots that will be displayed. Past locations that will be visualized.
- figsize (tuple) – (int,int) Size of the figure to display.
- dot_radius (int) – Radius of the first dot.
- linewidth (int) – Linewidth of the box to draw.
Returns: Matplotlib figure