def extractFeatures(self, train_data, test_data): # Construct Feature Extractor fe = FeatureExtractor() fe.buildVectorizer(train_data, self.config['featureKwargs']) # Make feature path if it doesnt exist if not os.path.exists(self.feature_path): os.mkdir(self.feature_path) # Check if train vectors already exist if os.path.exists(os.path.join(self.feature_path, 'train_vectors.npz')): # If it does, load them train_vectors = load_npz(os.path.join(self.feature_path, 'train_vectors.npz')) else: # Make the train vectors train_vectors = [fe.process(feature, train_data) for feature in self.config['features']] if len(train_vectors) > 1: train_vectors = numpy.concatenate(train_vectors, axis=1) else: train_vectors = train_vectors[0] # Save the train vectors save_npz(os.path.join(self.feature_path, 'train_vectors.npz'), train_vectors) # Check if test vectors already exist if os.path.exists(os.path.join(self.feature_path, 'test_vectors.npz')): # If it does, load them test_vectors = load_npz(os.path.join(self.feature_path, 'test_vectors.npz')) else: # Make the test vectors test_vectors = [fe.process(feature, test_data) for feature in self.config['features']] if len(test_vectors) > 1: test_vectors = numpy.concatenate(test_vectors, axis=1) else: test_vectors = test_vectors[0] # Save the test vectors save_npz(os.path.join(self.feature_path, 'test_vectors.npz'), test_vectors) return train_vectors, test_vectors
def extractFeatures(self, train_data, test_data): #Extract Features and pass them as concatenated arrays fe = FeatureExtractor(self.config['features'], self.config['featurePath'], self.config['featureKwargs']) fe.buildVectorizer(train_data) #Check for ALready done work if path.exists(self.config['featurePath'] + "train_data.pickle"): print("here's the error?") with open(self.config['featurePath'] + "train_data.pickle", "rb") as file: train_vectors = pickle.load(file) else: train_vectors = fe.process(train_data) with open(self.config['featurePath'] + "train_data.pickle", "wb+") as file: pickle.dump(train_vectors, file) if len(train_vectors) > 1: print("took option A") train_vectors = numpy.concatenate(train_vectors, axis=1) else: print("took option B") train_vectors = train_vectors[0] print(train_vectors.shape) print(train_vectors[1, :]) #Check for ALready done work if path.exists(self.config['featurePath'] + "test_data.pickle"): with open(self.config['featurePath'] + "test_data.pickle", "rb") as file: test_vectors = pickle.load(file) else: test_vectors = fe.process(test_data) with open(self.config['featurePath'] + "test_data.pickle", "wb+") as file: pickle.dump(test_vectors, file) if len(test_vectors) > 1: test_vectors = numpy.concatenate(test_vectors, axis=1) else: test_vectors = test_vectors[0] return train_vectors.toarray(), test_vectors.toarray()