コード例 #1
0
    def __save2database(self, imgIDs, cnn_feas):
        """
        save data to database(pickle files)
        save style: [(id_1, fea_1), .... , (id_batch_size, fea_batch_size)]
        """
        data_folder = self.data_path
        batch_size = self.batch_size

        def save(count, imgIDs, cnn_feas):
            fn = data_folder + count.__str__() + '.pkl'
            if os.path.isfile(fn):
                with open(fn, 'r') as f:
                    orgnl_data = pickle.load(f)
                    left_space = batch_size - len(orgnl_data)
                with open(fn, 'w') as f:
                    if left_space >= len(imgIDs):
                        pickle.dump(orgnl_data + zip(imgIDs, cnn_feas), f)
                    else:
                        pickle.dump(orgnl_data + zip(imgIDs[0:left_space], cnn_feas[0:left_space]), f)
                        save(count + 1, imgIDs[left_space::], cnn_feas[left_space::])
            else:
                with open(fn, 'w') as f:
                    if batch_size >= len(imgIDs):
                        pickle.dump(zip(imgIDs, cnn_feas), f)
                    else:
                        pickle.dump(zip(imgIDs[0:batch_size], cnn_feas[0:batch_size]), f)
                        save(count + 1, imgIDs[batch_size::], cnn_feas[batch_size::])

        file_names = get_files(data_folder)
        n_files = len(file_names)
        count = n_files if n_files != 0 else 1
        save(count, imgIDs, cnn_feas)
コード例 #2
0
    def __save2database(self, imgIDs, cnn_feas):
        """
        save data to database(pickle files)
        save style: [(id_1, fea_1), .... , (id_batch_size, fea_batch_size)]
        """
        data_folder = self.data_path
        batch_size = self.batch_size

        def save(count, imgIDs, cnn_feas):
            fn = data_folder + count.__str__() + '.pkl'
            if os.path.isfile(fn):
                with open(fn, 'r') as f:
                    orgnl_data = pickle.load(f)
                    left_space = batch_size - len(orgnl_data)
                with open(fn, 'w') as f:
                    if left_space >= len(imgIDs):
                        pickle.dump(orgnl_data + zip(imgIDs, cnn_feas), f)
                    else:
                        pickle.dump(orgnl_data + zip(imgIDs[0:left_space], cnn_feas[0:left_space]), f)
                        save(count + 1, imgIDs[left_space::], cnn_feas[left_space::])
            else:
                with open(fn, 'w') as f:
                    if batch_size >= len(imgIDs):
                        pickle.dump(zip(imgIDs, cnn_feas), f)
                    else:
                        pickle.dump(zip(imgIDs[0:batch_size], cnn_feas[0:batch_size]), f)
                        save(count + 1, imgIDs[batch_size::], cnn_feas[batch_size::])

        file_names = get_files(data_folder)
        n_files = len(file_names)
        count = n_files if n_files != 0 else 1
        save(count, imgIDs, cnn_feas)
コード例 #3
0
 def loadData(self):
     file_names = get_files(self.data_path)
     data = []
     for fn in file_names:
         with open(fn, 'r') as f:
             data += pickle.load(f)
     self.data = data
コード例 #4
0
 def loadData(self):
     file_names = get_files(self.data_path)
     data = []
     for fn in file_names:
         with open(fn, 'r') as f:
             data += pickle.load(f)
     self.data = data