コード例 #1
0
    def train(self, memory_size, input_size, num_samples, filename,stereo_mode):
        self.neural_network.memory_size = memory_size   
        self.neural_network.input_size = input_size        
        self.neural_network.AllocateNetworkMemories() 
        file_list = np.genfromtxt(filename, delimiter=',', names=True, dtype=np.dtype([('image',object), 
                                                                                            ('label', int), 
                                                                                            ('x', float), 
                                                                                            ('y', float), 
                                                                                            ('z',float),
                                                                                            ('rx', float), 
                                                                                            ('ry', float), 
                                                                                            ('rz',float), 
                                                                                            ('timestamp', object)]))

        for sample in xrange(file_list.shape[0]):
            if not sample%100:
                print "iterate:",sample
            if not stereo_mode :
                orig_image_file     = ImageProcProxy.readImageColor(file_list['image'][sample])
                image_file          = cv2.resize(orig_image_file, (params['input']['width'],params['input']['height']))
                image_crop          = image_file 
            else:
                image_file          = ImageProcProxy.readImageColor(file_list['image'][sample])
                image_crop          = ImageProcProxy.cropImage(image_file, 0, 0, params['input']['width'], params['input']['height'])
            image_gaus          = ImageProcProxy.applyGaussian(image_crop, 
                                        params['filter']['gaussian_radius'], 
                                        params['filter']['gaussian_sigma'])
            image_crop_int      = ImageProcProxy.convertBGR2INT(image_crop)
            image_gaus_int      = ImageProcProxy.convertBGR2INT(image_gaus)
            image_crop_vec      = ImageProcProxy.flattenImage(image_crop_int)
            image_gaus_vec      = ImageProcProxy.flattenImage(image_gaus_int)
            input_image = ImageProcProxy.concatImages(image_crop_vec, image_gaus_vec)
            input_class = file_list['label'][sample]
            self.neural_network.Train( input_image, input_class, sample)
コード例 #2
0
def LoadDataset(filename):
    file_list = np.genfromtxt(filename,
                              delimiter=',',
                              names=True,
                              dtype=np.dtype([('image', object),
                                              ('label', int), ('x', float),
                                              ('y', float), ('z', float),
                                              ('rx', float), ('ry', float),
                                              ('rz', float),
                                              ('timestamp', object)]))

    input_images = ImageProcProxy.emptyDataset(file_list.shape[0],
                                               params['input']['width'] * 2,
                                               params['input']['height'])
    image_file = ImageProcProxy.readImageColor(file_list['image'][0])
    image_crop = ImageProcProxy.cropImage(image_file, 0, 0,
                                          params['input']['width'],
                                          params['input']['height'])
    image_gaus = ImageProcProxy.applyGaussian(
        image_crop, params['filter']['gaussian_radius'],
        params['filter']['gaussian_sigma'])
    image_crop_int = ImageProcProxy.convertBGR2INT(image_crop)
    image_gaus_int = ImageProcProxy.convertBGR2INT(image_gaus)
    image_crop_vec = ImageProcProxy.flattenImage(image_crop_int)
    image_gaus_vec = ImageProcProxy.flattenImage(image_gaus_int)
    input_images[0] = ImageProcProxy.concatImages(image_crop_vec,
                                                  image_gaus_vec)
    return file_list.shape[0], input_images.shape[1], file_list.shape[0]
コード例 #3
0
def LoadDatasetAndCropImages(filename, imagepath):
    file_list = np.genfromtxt(filename, delimiter=',', names=True, dtype=np.dtype([('timestamp', object), ('x', float), ('y', float), ('label', int)]))

    input_images = np.zeros((file_list.shape[0], params['input']['height'], params['input']['width'], 3), dtype=np.uint8)
    for sample in xrange(file_list.shape[0]):
        image_file          = ImageProcProxy.readImageColor(imagepath + file_list['timestamp'][sample] + '.bb08.l.png')
        image_crop          = ImageProcProxy.cropImage(image_file, 0, 0, 
                                                       params['input']['width'], 
                                                       params['input']['height'])
        input_images[sample]= image_crop
        
    return input_images, file_list['label']
コード例 #4
0
ファイル: example_character.py プロジェクト: LCAD-UFES/SABGL
def LoadDataset(imagefile, labelfile, finalsize):
    loaded = np.fromfile(file=open(imagefile),dtype=np.uint8)
    images = loaded[16:].reshape((-1,28,28))
    
    loaded = np.fromfile(file=open(labelfile),dtype=np.uint8)
    labels = loaded[8:].reshape((images.shape[0]))
    
    input_images = ImageProcProxy.emptyDataset(images.shape[0], params['input']['width'], params['input']['height'])
    for sample in xrange(images.shape[0]):
        image_resized       = ImageProcProxy.resizeInterLinear(images[sample], params['input']['width'], params['input']['height'])
        image_gaussian      = ImageProcProxy.applyGaussian(image_resized, 
                                    params['filter']['gaussian_radius'], 
                                    params['filter']['gaussian_sigma'])
        image_vector        = ImageProcProxy.flattenImage(image_gaussian)
        input_images[sample]= image_vector
        
    return input_images[:finalsize], labels[:finalsize]
コード例 #5
0
ファイル: example_character.py プロジェクト: thiagorjes/SABGL
def LoadDataset(imagefile, labelfile, finalsize):
    loaded = np.fromfile(file=open(imagefile), dtype=np.uint8)
    images = loaded[16:].reshape((-1, 28, 28))

    loaded = np.fromfile(file=open(labelfile), dtype=np.uint8)
    labels = loaded[8:].reshape((images.shape[0]))

    input_images = ImageProcProxy.emptyDataset(images.shape[0],
                                               params['input']['width'],
                                               params['input']['height'])
    for sample in xrange(images.shape[0]):
        image_resized = ImageProcProxy.resizeInterLinear(
            images[sample], params['input']['width'],
            params['input']['height'])
        image_gaussian = ImageProcProxy.applyGaussian(
            image_resized, params['filter']['gaussian_radius'],
            params['filter']['gaussian_sigma'])
        image_vector = ImageProcProxy.flattenImage(image_gaussian)
        input_images[sample] = image_vector

    return input_images[:finalsize], labels[:finalsize]
コード例 #6
0
def LoadDatasetAndCropImages(filename, imagepath):
    file_list = np.genfromtxt(filename,
                              delimiter=',',
                              names=True,
                              dtype=np.dtype([('image', object),
                                              ('label', int), ('x', float),
                                              ('y', float), ('z', float),
                                              ('rx', float), ('ry', float),
                                              ('rz', float),
                                              ('timestamp', object)]))

    input_images = np.zeros((file_list.shape[0], params['input']['height'],
                             params['input']['width'], 3),
                            dtype=np.uint8)
    for sample in xrange(file_list.shape[0]):
        image_file = ImageProcProxy.readImageColor(file_list['image'][sample])
        image_crop = ImageProcProxy.cropImage(image_file, 0, 0,
                                              params['input']['width'],
                                              params['input']['height'])
        input_images[sample] = image_crop

    return input_images, file_list['label']
コード例 #7
0
def LoadDataset(filename, imagepath):
    file_list = np.genfromtxt(filename, delimiter=',', names=True, dtype=np.dtype([('timestamp', object), ('x', float), ('y', float), ('label', int)]))

    input_images = ImageProcProxy.emptyDataset(file_list.shape[0], 
                                               params['input']['width'] * 2, 
                                               params['input']['height'])
    for sample in xrange(file_list.shape[0]):
        image_file          = ImageProcProxy.readImageColor(imagepath + file_list['timestamp'][sample] + '.bb08.l.png')
        image_crop          = ImageProcProxy.cropImage(image_file, 0, 0, 
                                                       params['input']['width'], 
                                                       params['input']['height'])
        image_gaus          = ImageProcProxy.applyGaussian(image_crop, 
                                    params['filter']['gaussian_radius'], 
                                    params['filter']['gaussian_sigma'])
        image_crop_int      = ImageProcProxy.convertBGR2INT(image_crop)
        image_gaus_int      = ImageProcProxy.convertBGR2INT(image_gaus)
        image_crop_vec      = ImageProcProxy.flattenImage(image_crop_int)
        image_gaus_vec      = ImageProcProxy.flattenImage(image_gaus_int)
        input_images[sample]= ImageProcProxy.concatImages(image_crop_vec, image_gaus_vec)
    return input_images, file_list['label'], file_list['x'], file_list['y']
コード例 #8
0
def ProcessImage(image_crop, pixel_range=0):
    x = uniform(-pixel_range, pixel_range)
    y = uniform(-pixel_range, pixel_range)
    image_trans = ImageProcProxy.translateImage(image_crop, x, y)
    #ImageProcProxy.showImageBGR(image_trans)
    image_gaus = ImageProcProxy.applyGaussian(
        image_trans, params['filter']['gaussian_radius'],
        params['filter']['gaussian_sigma'])
    image_crop_int = ImageProcProxy.convertBGR2INT(image_crop)
    image_gaus_int = ImageProcProxy.convertBGR2INT(image_gaus)
    image_crop_vec = ImageProcProxy.flattenImage(image_crop_int)
    image_gaus_vec = ImageProcProxy.flattenImage(image_gaus_int)
    input_image = ImageProcProxy.concatImages(image_crop_vec, image_gaus_vec)

    return input_image
コード例 #9
0
def ProcessImage(image_crop, pixel_range=0):
    x = uniform(-pixel_range, pixel_range)
    y = uniform(-pixel_range, pixel_range)
    image_trans         = ImageProcProxy.translateImage(image_crop, x, y)
    #ImageProcProxy.showImageBGR(image_trans)
    image_gaus          = ImageProcProxy.applyGaussian(image_trans, 
                            params['filter']['gaussian_radius'], 
                            params['filter']['gaussian_sigma'])
    image_crop_int      = ImageProcProxy.convertBGR2INT(image_crop)
    image_gaus_int      = ImageProcProxy.convertBGR2INT(image_gaus)
    image_crop_vec      = ImageProcProxy.flattenImage(image_crop_int)
    image_gaus_vec      = ImageProcProxy.flattenImage(image_gaus_int)
    input_image         = ImageProcProxy.concatImages(image_crop_vec, image_gaus_vec)
    
    return input_image
コード例 #10
0
def LoadDataset(filename, imagepath):
    file_list = np.genfromtxt(filename, dtype=np.dtype([('Filename','S21'), ('Width', int), ('Height', int), ('roi_x1', int), ('roi_y1', int), ('roi_x2', int), ('roi_y2', int), ('classId', int)]))

    ImageProcProxy.createCLAHE(clipLimit=1.4, tileGridSize=(2,2))
    input_images = ImageProcProxy.emptyDataset(file_list.shape[0], params['input']['width'], params['input']['height'])
    for sample in xrange(file_list.shape[0]):
        image_file          = ImageProcProxy.readImageColor(imagepath + file_list['Filename'][sample])
        image_roi           = ImageProcProxy.cropImage(image_file, 
                                                       file_list['roi_x1'][sample], file_list['roi_y1'][sample], 
                                                       file_list['roi_x2'][sample], file_list['roi_y2'][sample])
        image_clahe         = ImageProcProxy.emptyLike(image_roi)
        image_clahe[:,:,0]  = ImageProcProxy.applyCLAHE(image_roi[:,:,0])
        image_clahe[:,:,1]  = ImageProcProxy.applyCLAHE(image_roi[:,:,1])
        image_clahe[:,:,2]  = ImageProcProxy.applyCLAHE(image_roi[:,:,2])
        image_resized       = ImageProcProxy.resizeInterLinear(image_clahe, 
                                    params['input']['width'], 
                                    params['input']['height'])
        image_gaussian      = ImageProcProxy.applyGaussian(image_resized, 
                                    params['filter']['gaussian_radius'], 
                                    params['filter']['gaussian_sigma'])
        image_int           = ImageProcProxy.convertBGR2INT(image_gaussian)
        image_vector        = ImageProcProxy.flattenImage(image_int)
        input_images[sample]= image_vector
        
    return input_images, file_list['classId']
コード例 #11
0
def LoadDataset(filename, imagepath):
    file_list = np.genfromtxt(filename,
                              dtype=np.dtype([('Filename', 'S21'),
                                              ('Width', int), ('Height', int),
                                              ('roi_x1', int), ('roi_y1', int),
                                              ('roi_x2', int), ('roi_y2', int),
                                              ('classId', int)]))

    ImageProcProxy.createCLAHE(clipLimit=1.4, tileGridSize=(2, 2))
    input_images = ImageProcProxy.emptyDataset(file_list.shape[0],
                                               params['input']['width'],
                                               params['input']['height'])
    for sample in xrange(file_list.shape[0]):
        image_file = ImageProcProxy.readImageColor(
            imagepath + file_list['Filename'][sample])
        image_roi = ImageProcProxy.cropImage(image_file,
                                             file_list['roi_x1'][sample],
                                             file_list['roi_y1'][sample],
                                             file_list['roi_x2'][sample],
                                             file_list['roi_y2'][sample])
        image_clahe = ImageProcProxy.emptyLike(image_roi)
        image_clahe[:, :, 0] = ImageProcProxy.applyCLAHE(image_roi[:, :, 0])
        image_clahe[:, :, 1] = ImageProcProxy.applyCLAHE(image_roi[:, :, 1])
        image_clahe[:, :, 2] = ImageProcProxy.applyCLAHE(image_roi[:, :, 2])
        image_resized = ImageProcProxy.resizeInterLinear(
            image_clahe, params['input']['width'], params['input']['height'])
        image_gaussian = ImageProcProxy.applyGaussian(
            image_resized, params['filter']['gaussian_radius'],
            params['filter']['gaussian_sigma'])
        image_int = ImageProcProxy.convertBGR2INT(image_gaussian)
        image_vector = ImageProcProxy.flattenImage(image_int)
        input_images[sample] = image_vector

    return input_images, file_list['classId']