Beispiel #1
0
 def sample(self, n_per_class=10, preload=False):
     import random
     tran = listvalues(self.trans)[0]
     splt = listvalues(self.splits)[0]
     the_sample = []
     for cls in listvalues(self.classes):
         cls: ImageDatasetClass
         folder = cls.folder(splt, tran)
         im_paths = folder.paths
         num = len(im_paths)
         assert num > n_per_class
         already_took = []
         n = 0
         while n < n_per_class:
             i = random.randrange(0, num)
             if i in already_took:
                 continue
             else:
                 the_im = ImageDatasetImage(File(im_paths[i]), self, tran,
                                            splt, cls)
                 if preload:
                     the_im.load()
                 the_sample.append(the_im)
                 n += 1
                 already_took += [i]
     return the_sample
Beispiel #2
0
    def violin(self):
        fd = PlotData(
            y=[y.tolist() for y in listvalues(self.data)],
            item_type='violin',
            **self._common(),
        )

        return fd
Beispiel #3
0
 def bar(self):
     means = {k: np.nanmean(v) for k, v in self.data.items()}
     fd = PlotData(
         y=listvalues(means),
         item_type='bar',
         **self._common(),
     )
     return fd
Beispiel #4
0
 def __init__(self, name):
     self.folder = OM_IM_DATA_ROOT[name]
     self.metadata_file = self.folder['metadata.json']
     self.trans = {_RAW: ImageDatasetTransformation(self, _RAW)}
     self.splits = {
         n: ImageDatasetSplit(self, n)
         for n in [_TRAIN, _TEST, _EVAL]
     }
     if not ismac():
         self.classes = ClassSet([
             ImageDatasetClass(name=File(class_folder).name,
                               index=i,
                               dataset=self) for i, class_folder in esorted(
                                   listvalues(self.splits)[0].folder(
                                       listvalues(self.trans)[0]).paths)
         ])
     if not ismac():
         self.verify()
Beispiel #5
0
 def vals(self) -> li:
     return li(listvalues(self))
Beispiel #6
0
def dict_to_table(d):
    from mlib.math import sigfig_if_num
    return [[''] + [k for k in listvalues(d)[0].keys()]] + [
        [k] + listvalues(v).map(sigfig_if_num) for k, v in d.items()
    ]