Exemplo n.º 1
0
    def readRotations(self):
        #Unpacks the map parameters
        inputStream = open(self.__fileName, 'rb')
        somTools.ignoreHeaderComments(inputStream)

        self.__numberOfImages = struct.unpack("i", inputStream.read(4))[0]
        self.__somWidth = struct.unpack("i", inputStream.read(4))[0]
        self.__somHeight = struct.unpack("i", inputStream.read(4))[0]
        self.__somDepth = struct.unpack("i", inputStream.read(4))[0]

        print ("images: " + str(self.__numberOfImages))
        print ("width: " + str(self.__somWidth))
        print ("height: " + str(self.__somHeight))
        print ("depth: " + str(self.__somDepth))

        #Unpacks data
        try:
            while True:
                dataF = numpy.ones(self.__somWidth * self.__somHeight * self.__somDepth * self.__numberOfImages)
                dataR = numpy.ones(self.__somWidth * self.__somHeight * self.__somDepth * self.__numberOfImages)
                for i in range(self.__somWidth * self.__somHeight * self.__somDepth * self.__numberOfImages):
                    dataF[i] = struct.unpack_from("?", inputStream.read(1))[0]
                    dataR[i] = struct.unpack_from("f", inputStream.read(4))[0]
                self.__flipped.append(dataF)
                self.__rotations.append(dataR)

        except:
            inputStream.close()

        self.__flipped = numpy.array(self.__flipped)
        self.__rotations = numpy.array(self.__rotations)

        print ("rotations loaded")
        inputStream.close()
Exemplo n.º 2
0
    def readMap(self):
        #Unpacks the map parameters
        inputStream = open(self.__fileName, 'rb')
        somTools.ignoreHeaderComments(inputStream)

        self.__numberOfChannels = struct.unpack("i", inputStream.read(4))[0]
        self.__somWidth = struct.unpack("i", inputStream.read(4))[0]
        self.__somHeight = struct.unpack("i", inputStream.read(4))[0]
        self.__somDepth = struct.unpack("i", inputStream.read(4))[0]
        self.__neuronWidth = struct.unpack("i", inputStream.read(4))[0]
        self.__neuronHeight = struct.unpack("i", inputStream.read(4))[0]

        print ("channels: " + str(self.__numberOfChannels))
        print ("width: " + str(self.__somWidth))
        print ("height: " + str(self.__somHeight))
        print ("depth: " + str(self.__somDepth))
        print ("neurons: " + str(self.__neuronWidth) +"x" + str(self.__neuronHeight))
        #Unpacks data
        try:
            while True:
                data = numpy.ones(self.__neuronWidth * self.__neuronHeight * self.__numberOfChannels)
                for i in range(self.__neuronWidth * self.__neuronHeight * self.__numberOfChannels):
                    data[i] = struct.unpack_from("f", inputStream.read(4))[0]
                self.__neurons.append(data)
        except:
            inputStream.close()
        self.__neurons = numpy.array(self.__neurons)

        print (str(len(self.__neurons)) + " neurons loaded")
        inputStream.close()
Exemplo n.º 3
0
    def readMap(self):
        #Unpacks the map parameters
        inputStream = open(self.__fileName, 'rb')
        somTools.ignoreHeaderComments(inputStream)  # find end of header

        self.__numberOfImages = struct.unpack("i", inputStream.read(4))[0]
        self.__somWidth = struct.unpack("i", inputStream.read(4))[0]
        self.__somHeight = struct.unpack("i", inputStream.read(4))[0]
        self.__somDepth = struct.unpack("i", inputStream.read(4))[0]

        print("images: " + str(self.__numberOfImages))
        print("width: " + str(self.__somWidth))
        print("height: " + str(self.__somHeight))
        print("depth: " + str(self.__somDepth))

        start = inputStream.tell()
        if os.path.getsize(
                self.__fileName
        ) < self.__numberOfImages * self.__somWidth * self.__somHeight * self.__somDepth * 4 + start:
            self.__shape = "hex"
        else:
            self.__shape = "box"

        #Unpacks data
        hexSize = int(1.0 + 6.0 * (((self.__somWidth - 1) / 2.0 + 1.0) *
                                   (self.__somHeight - 1) / 4.0))
        try:
            while True:
                if self.__shape == "box":
                    data = numpy.ones(self.__somWidth * self.__somHeight *
                                      self.__somDepth)
                    for i in range(self.__somWidth * self.__somHeight *
                                   self.__somDepth):
                        data[i] = struct.unpack_from("f",
                                                     inputStream.read(4))[0]
                    self.__maps.append(data)
                else:

                    data = numpy.ones(hexSize)
                    for i in range(hexSize):
                        data[i] = struct.unpack_from("f",
                                                     inputStream.read(4))[0]
                    self.__maps.append(data)

        except:
            inputStream.close()
        self.__maps = numpy.array(self.__maps)
        print(str(len(self.__maps)) + " maps loaded")