Ejemplo n.º 1
0
    def __getitem__(self, ind):
        if isinstance(self.indexes, int):
            if ind != 0:
                raise OutOfBoundsError(f"Got index {ind} for dataset of length 1")
            index = self.indexes
        else:
            index = self.indexes[ind]
        self._init_ds()
        d = {}
        for key in self._ds._tensors.keys():
            if key not in self.key_list:
                continue
            split_key = key.split("/")
            cur = d
            for i in range(1, len(split_key) - 1):
                if split_key[i] not in cur.keys():
                    cur[split_key[i]] = {}
                cur = cur[split_key[i]]

            item = self._get_active_item(key, index)
            if not isinstance(item, bytes) and not isinstance(item, str):
                t = item
                if self.inplace:
                    if t.dtype == "uint16":
                        t = t.astype("int32")
                    elif t.dtype == "uint32" or t.dtype == "uint64":
                        t = t.astype("int64")
                    t = torch.tensor(t)
                cur[split_key[-1]] = t
        d = self._do_transform(d)
        if self.inplace & (self.output_type != dict) & (isinstance(d, dict)):
            d = self.output_type(d.values())
        return d
Ejemplo n.º 2
0
    def create(cls, obj, context=None, bounded=False):
        typ = type(obj)
        if typ is Bbox:
            obj = obj
        elif typ in (list, tuple):
            obj = Bbox.from_slices(obj, context, bounded)
        elif typ is Vec:
            obj = Bbox.from_vec(obj)
        elif typ is str:
            obj = Bbox.from_filename(obj)
        elif typ is dict:
            obj = Bbox.from_dict(obj)
        else:
            raise NotImplementedError(
                "{} is not a Bbox convertible type.".format(typ))

        if context and bounded:
            if not context.contains_bbox(obj):
                raise OutOfBoundsError(
                    "{} did not fully contain the specified bounding box {}.".
                    format(context, obj))

        return obj
Ejemplo n.º 3
0
def check_bounds(val, low, high):
    if val > high or val < low:
        raise OutOfBoundsError(
            'Value {} cannot be outside of inclusive range {} to {}'.format(
                val, low, high))
    return val