示例#1
0
文件: aerial.py 项目: olavvatne/CNN
    def create_data_from_image(self ,image_path):
        print("Create data patches for model")
        dim = self.dim_label
        image = self.open_image(image_path)
        dp = 2* self.padding

        vertical = int((image.shape[0] - dp) / dim)
        horizontal = int((image.shape[1] - dp) / dim)
        number_of_patches = vertical * horizontal

        data = np.empty((number_of_patches, self.dim_data*self.dim_data*3), dtype=theano.config.floatX)
        label = np.empty((number_of_patches, dim*dim), dtype=theano.config.floatX)

        idx = 0
        for i in range(vertical):
            for j in range(horizontal):
                img_i = i * dim
                img_j = j * dim
                image_patch = from_rgb_to_arr(image[img_i: img_i + dim + dp, img_j: img_j + dim + dp])

                if self.normalize:
                    image_patch = normalize(image_patch, self.std)
                data[idx] = image_patch
                idx += 1

        aerial = AerialDataset()
        return aerial.shared_dataset([data, label], cast_to_int=True), (vertical, horizontal)
示例#2
0
 def _create_dataset(self, set_name):
     dim = (self.dataset_config.input_dim, self.dataset_config.output_dim)
     path = self.dataset_path
     preprocessing = self.dataset_config.use_preprocessing
     print("---- Using preprossing: {}".format(preprocessing))
     std = self.dataset_config.dataset_std
     samples_per_image = 200
     creator = Creator(path, dim=dim, preproccessing=preprocessing, std=std)
     creator.load_dataset()
     #Creating a shared variable of sampled test data
     raw_set = None
     if set_name == "valid":
         raw_set = creator.valid
     else:
         raw_set = creator.test
     aerial = AerialDataset()
     return aerial.shared_dataset(creator.sample_data(raw_set, samples_per_image), cast_to_int=True)
示例#3
0
 def _create_dataset(self, set_name):
     dim = (self.dataset_config.input_dim, self.dataset_config.output_dim)
     path = self.dataset_path
     preprocessing = self.dataset_config.use_preprocessing
     print("---- Using preprossing: {}".format(preprocessing))
     std = self.dataset_config.dataset_std
     samples_per_image = 200
     creator = Creator(path, dim=dim, preproccessing=preprocessing, std=std)
     creator.load_dataset()
     #Creating a shared variable of sampled test data
     raw_set = None
     if set_name == "valid":
         raw_set = creator.valid
     else:
         raw_set = creator.test
     aerial = AerialDataset()
     return aerial.shared_dataset(creator.sample_data(
         raw_set, samples_per_image),
                                  cast_to_int=True)