예제 #1
0
 def __init__(self, layerxml, params, prev_layer = None, windowshape = None):
     super(InputLayerSW, self).__init__(layerxml, params)
     
     # InputLayerSW must be the first layer
     if prev_layer != None:
         raise NotImplementedError()
     
     self.data_info = []   
     for d in layerxml.findall('data'):
         data_dir = d.find('dir').text + '/'
         self.data_info.append((data_dir))
    
     self.prepro_type = layerxml.find('preprocessing').text
     self.windowshape = windowshape
     if self.windowshape == None:
         #TODO: Parse from layer_xml, not hardcode
         self.windowshape = (int(layerxml.find('windowshape/h').text), 
                             int(layerxml.find('windowshape/w').text), 
                             int(layerxml.find('windowshape/d').text))
             
     if not params.load_weights:
         self.data = DataSlidingWindow(points=params.pnt_nos)
         self.data.load_picked_data(params.shared_op_dir)
         for dir in self.data_info:
             print 'Adding  data from: ' + dir            
             self.data.add_to_dataset(dir)
         self.data.load_data(self.windowshape, shuffle=False)
         self.data.save_picked_data(params.shared_op_dir) 
     params.imshape = self.windowshape
     
     self.out_size = (params.batch_size, params.imshape[2], params.imshape[0], params.imshape[1])
     # TODO: Is this in_size correct?
     self.in_size = (params.batch_size, params.imshape[2], params.imshape[0], params.imshape[1])
     
     print("InputLayerSW out_size: " + str(self.out_size))
예제 #2
0
class InputLayerSW(Layer):
    type = 'InputLayerSW'
    
    def __init__(self, layerxml, params, prev_layer = None, windowshape = None):
        super(InputLayerSW, self).__init__(layerxml, params)
        
        # InputLayerSW must be the first layer
        if prev_layer != None:
            raise NotImplementedError()
        
        self.data_info = []   
        for d in layerxml.findall('data'):
            data_dir = d.find('dir').text + '/'
            self.data_info.append((data_dir))
       
        self.prepro_type = layerxml.find('preprocessing').text
        self.windowshape = windowshape
        if self.windowshape == None:
            #TODO: Parse from layer_xml, not hardcode
            self.windowshape = (int(layerxml.find('windowshape/h').text), 
                                int(layerxml.find('windowshape/w').text), 
                                int(layerxml.find('windowshape/d').text))
                
        if not params.load_weights:
            self.data = DataSlidingWindow(points=params.pnt_nos)
            self.data.load_picked_data(params.shared_op_dir)
            for dir in self.data_info:
                print 'Adding  data from: ' + dir            
                self.data.add_to_dataset(dir)
            self.data.load_data(self.windowshape, shuffle=False)
            self.data.save_picked_data(params.shared_op_dir) 
        params.imshape = self.windowshape
        
        self.out_size = (params.batch_size, params.imshape[2], params.imshape[0], params.imshape[1])
        # TODO: Is this in_size correct?
        self.in_size = (params.batch_size, params.imshape[2], params.imshape[0], params.imshape[1])
        
        print("InputLayerSW out_size: " + str(self.out_size))
    
    def compute(self, input, params):
        self.output = input.reshape((params.batch_size, params.imshape[2], params.imshape[0], params.imshape[1]))  

    def write_log(self, params):
        # TODO: Fix this (I assume the data format was changed at some point)
        #tools.write_image(self.data.train_set_x.get_value(), (self.windowshape[0],self.windowshape[1], self.windowshape[2]), params.op_dir + 'train_x_before_preprocess.png')  
        #tools.write_image_multiple(self.data.train_set_y.get_value(), (1,1), params.pnt_nos, params.op_dir + 'train_y_slice-{0:d}.png')
        #tools.write_image(self.data.valid_set_x.get_value(), (self.windowshape[0],self.windowshape[1], self.windowshape[2]), params.op_dir + 'valid_x_before_preprocess.png')  
        #tools.write_image_multiple(self.data.valid_set_y.get_value(), (1,1), params.pnt_nos, params.op_dir + 'valid_y_slice-{0:d}.png')
        if len(self.data.X_names['test']) > 0:
            print 'Data format changed'