Ejemplo n.º 1
0
    def __data_generation(self, list_IDs_temp):
        X = np.empty((self.batch_size, *self.img_size))

        if self.labels is not None:  # training phase
            Y = np.empty((self.batch_size, 6), dtype=np.float32)

            for i, ID in enumerate(list_IDs_temp):
                img = _read(self.img_dir + ID + ".dcm", self.img_size)
                if self.augmentations:
                    img = np.float32(img)
                    augmented = self.augmentations(image=img)
                    X[i, ] = augmented['image']
                Y[i, ] = self.labels.loc[ID].values

            return X, Y

        else:  # test phase
            for i, ID in enumerate(list_IDs_temp):
                X[i, ] = _read(self.img_dir + ID + ".dcm", self.img_size)

            return X
Ejemplo n.º 2
0
    def read(self, f, file_name=None):

        self.file_name = file_name

        # Read the header.
        magic = read_OP(f)

        if magic == XMAGIC:
            self.signed = False
        elif magic == SMAGIC:
            self.signed = True
        else:
            raise self.error("Invalid magic number")

        if self.signed:
            length = _read(f, ">I")
            self.signature = f.read(length)

        self.runtime_flag = RuntimeFlag(read_OP(f))
        self.stack_extent = read_OP(f)
        self.code_size = read_OP(f)
        self.data_size = read_OP(f)
        self.type_size = read_OP(f)
        self.link_size = read_OP(f)
        self.entry_pc = read_OP(f)
        self.entry_type = read_OP(f)

        # Read the other sections.
        self.read_code(f)
        self.read_types(f)
        self.read_data(f)

        self.module_name = read_C(f)

        self.read_link(f)

        if self.runtime_flag.contains(RuntimeFlag.HASLDT):
            self.read_ldt(f)

        if self.runtime_flag.contains(RuntimeFlag.HASEXCEPT):
            self.read_exceptions(f)

        self.path = read_C(f)
Ejemplo n.º 3
0
 def test_read_fail(self):
     string = utils._read(self.sample_file)
     self.assertNotIn(string, "Z")
Ejemplo n.º 4
0
 def test_read(self):
     string = utils._read(self.sample_file)
     self.assertIn(string,
                   "eyJSYWd1bCI6ICJJbmRpYW4iLCAiUmljYXJkbyI6ICJQb2xhY28iLCAiRmxhbWFyaW9uIjogIkJyYXppbGlhbiJ9")
Ejemplo n.º 5
0
 def __init__(self, sample_file):
     self.sample_file = sample_file
     self.decoded_json = json.loads(
         utils._base64ToString(utils._read(self.sample_file)))
Ejemplo n.º 6
0
    def read(self, f):

        self.sig = _read(f, ">I")  # unsigned for hashes
        self.name = read_C(f)

        return self
Ejemplo n.º 7
0
    def read_data(self, f):

        # Use a dictionary to map pointers in the module's data area to items.
        self.data = {}

        # Maintain a list of individual data items for easy inspection.
        self.data_items = []

        # Use a list as a load address stack with an initial base address of 0.
        addresses = []
        base = 0
        type_ = None

        while True:

            at = f.tell()

            code = read_B(f)
            if code == 0:
                break

            count = code & 0x0f
            array_type = code >> 4

            if count == 0:
                count = read_OP(f)

            offset = read_OP(f)

            if not 1 <= array_type <= 8:
                raise self.error("Unknown type in data item at 0x%x" % at)

            elif array_type == 5:
                # Array
                type_index = _read(f, ">I")
                length = _read(f, ">I")
                type_ = self.types[type_index]
                #print "Array", offset

            elif array_type == 6:
                # Set array index
                index = _read(f, ">I")
                # Store the current base first.
                addresses.append(base)
                #print "Set", base, offset, index
                base = offset + index

            elif array_type == 7:
                # Restore load address
                base = addresses.pop()
                type_ = None
                #print "Restore", base, offset

            else:
                #print "Data", offset
                address = base + offset
                item = Data(base, offset, array_type, type_)
                item.read(f, count)
                self.data_items.append(item)
                if address in self.data:
                    print "Overwriting existing data item at %x." % address
                self.data[address] = item