Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.get_widget().observe(fn, names=names)
def update_ui(self, uindex):
raise Exception('Do not call update_ui on base class, Innotation {} with name {}'.format(type(self), self.name))
def update_data(self, uindex):
raise Exception('Do not call update_data on an input-only class, Innotation {} with name {}'.format(type(self), self.name))
def contains_widget(self, widget):
return self.get_widget() == widget
def list_innotations_tree(self):
return [self]
class ImageInnotation(Innotation, DataMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.width = kwargs.get('width', 0)
self.height = kwargs.get('height', 0)
self.path = kwargs.get('path', '')
self.transform = kwargs.get('transform', None)
self.annotation_styles = kwargs.get('annotation_styles', {})
self.colorspace = 'BGR'
if 'colorspace' in kwargs:
self.colorspace = kwargs['colorspace']
self.max_repeats += 1
self.get_widget().set_max_repeats(self.max_repeats)
self.watchlist.add(Watcher(name=name, repeat_index=repeat_index))
def get_current_watcher(self):
return self.watchlist[self.get_widget().rect_index]
def set_current_watcher(self, name, repeat_index):
self.get_widget().rect_index = self.watchlist.get_watcher_index(name, repeat_index)
def get_rect_for_watcher(self, name, repeat_index):
watcher_index = self.watchlist.get_watcher_index(name, repeat_index)
return self.get_widget().rects[watcher_index*4:(watcher_index+1)*4]
class BoundingBoxInnotation(Innotation, DataMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.source = kwargs.get('source', None)
self.sourcedw = None
def post_register(self, datamanager):
if self.source is not None:
self.sourcedw = datamanager.get_data_wrapper_by_name(self.source)
if self.sourcedw is None:
raise Exception('ImageInnotation named {} not found but specified as source attribute for BoundingBoxInnotation'.format(self.source))
if not isinstance(self.sourcedw, ImageInnotation):
def rectIndexChanged(self, change):
if self.sourcedw is not None:
#if self.sourcedw.get_widget().rect_index == self.repeat_index:
watcher = self.sourcedw.get_current_watcher()
if watcher.name == self.name and watcher.repeat_index == self.repeat_index:
self.get_widget().add_class('bounding-box-active')
else:
self.get_widget().remove_class('bounding-box-active')
def widget_clicked(self, w):
if self.sourcedw is not None:
self.sourcedw.set_current_watcher(self.name, self.repeat_index)
class MultiClassInnotation(Innotation, DataMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Just a 1-dim array with values corresponding to class numbers e.g. 0-5
self.datadepth = 'simple'
self.dims = 1
if hasattr(self._get_data(0), '__len__'):
self.dims = 2
if self.dims > 1:
if len(self._get_data(0)) == 1:
self.datadepth = 'colvector' # A column vector corresponding to class numbers directly
else:
class BinaryClassInnotation(MultiClassInnotation):
def _guess_classes(self):
self.classes = ['False', 'True']
def _create_widget(self):
return Checkbox(description=self.desc, layout=self.layout, disabled=self.disabled)
def update_ui(self, uindex):
self.get_widget().value = bool(self._calc_class_index(uindex) == 1)
def _get_widget_value(self):
return self.classes[self.get_widget().value and 1 or 0]
class TextInnotation(Innotation, DataMixin):
def __init__(self, *args, **kwargs):
self.multiline = kwargs.get('multiline', True)
super().__init__(*args, **kwargs)
def _create_widget(self):
if self.multiline:
return Textarea(layout=self.layout, disabled=self.disabled)
return Text(layout=self.layout, disabled=self.disabled)
def update_ui(self, uindex):
self.get_widget().value = str(self._get_data(uindex))
def update_data(self, uindex):
def _add_to_alldws(self, dw, l):
for onedw in dw.list_innotations_tree():
name = onedw.name
if name in self.alldws:
raise Exception('Duplicate Innotation {}'.format(name))
self.alldws[name] = onedw
# Check number of rows is the same and not zero
if isinstance(dw, DataMixin):
this_len = len(dw)
if l == -1:
if this_len == 0:
raise Exception('Innotation {} {} has 0 data rows'.format(type(dw), name))
l = this_len
elif l != this_len:
raise Exception('Innotations must all have same number of rows: {} {} has a different number of data rows than previous Innotations'.format(type(dw), name))
return l