def extract_and_predict(self, image, featureSet=None): # Use the classifier's configured feature set if not featureSet: featureSet = self.featureSet extractedFeatures = FeatureExtractor.extract(image, featureSet) return self.model.predict([extractedFeatures])
def main(): webpages_dir = os.path.join(util.ROOT, 'data/weps2007_data_1.1/traininig/web_pages') fe = FeatureExtractor() ff = FeatureFilter() for name in os.listdir(webpages_dir): print 'begin clustering %s' % name reader = FileReader(webpages_dir, name) description = reader.read_description() pc = PersonCorpus(name) fm = FeatureMapper() for rank in description: doc_meta = {} html_path = os.path.join(webpages_dir, name, 'raw', rank, 'index.html') content = text_extract(html_path) features, wordcount = fe.extract(content) doc_meta['word_num'] = wordcount good_features = ff.filter(features) vec = FeatureVector(good_features, fm) pc.add_vector(vec) pc.compute_matrix() pc.dump_matrix()
class RealWorldTester(object): def __init__(self, fileloc, clf, ss=None): self.clf = clf self.standardizer = ss self.file_loc = fileloc self.file_handler = FileHandler(self.file_loc) self.file_handler.set_file_extensions((".wav")) self.file_handler.create_all_file_list() self.file_handler.split_train_test() self.extractor = FeatureExtractor() def classify_clip(self): y = [] for tf in self.file_handler.train_files: cur_clips = self.file_handler.file_to_clips(tf, short=False) for clip in cur_clips: self.extractor.set_clip(clip) features = np.reshape(self.extractor.extract(), (1, -1)) features = self.standardizer.transform(features) pred = self.clf.predict(features) y.append(pred[0]) return y def reorder_clip(self, classification): fs, raw = wavfile.read(self.file_handler.train_files[0]) raw = raw / (2**15 - 1) sil = [] noise = [] music = [] impure = [] pure = [] count = 0 sr = fs for c in classification: if c == 's': sil.extend(raw[count * sr:(count + 1) * sr]) elif c == 'n': noise.extend(raw[count * sr:(count + 1) * sr]) elif c == 'm': music.extend(raw[count * sr:(count + 1) * sr]) elif c == 'i': impure.extend(raw[count * sr:(count + 1) * sr]) elif c == 'p': pure.extend(raw[count * sr:(count + 1) * sr]) count += 1 rearranged = sil + noise + music + impure + pure rearranged = np.asarray(rearranged, dtype="float32") wavfile.write("rearranged.wav", fs, rearranged) def plot_classification(self): classification = self.classify_clip() class_colors = ["#4286f4", "#ff3855", "#92ff5b", "#f4c60e", "#111111"] p_sp = [] im_sp = [] music = [] noise = [] sil = [] count = 0 for c in classification: if c == 'p': p_sp.append(count) elif c == 'i': im_sp.append(count) elif c == 'm': music.append(count) elif c == 'n': noise.append(count) elif c == 's': sil.append(count) count += 1 print(sil) print(noise) print(music) print(im_sp) print(p_sp) self.reorder_clip(classification) plt.figure() plt.plot(sil, [0] * len(sil), 'ko') plt.plot(noise, [1] * len(noise), 'yo') plt.plot(music, [2] * len(music), 'ro') plt.plot(im_sp, [3] * len(im_sp), 'bo') plt.plot(p_sp, [4] * len(p_sp), 'go') plt.xlabel("Time (seconds)") plt.title("God's Plan (30 Seconds)") plt.yticks( [0, 1, 2, 3, 4], ['silence', 'noise', 'music', 'impure speech', 'pure speech']) plt.show()
args = parser.parse_args() if not os.path.exists(args.extractor): print "Path to extractor '%s' not found" % args.extractor sys.exit(-1) if args.path_to_audio is None: args.path_to_audio = "audio/"+args.collection_name if args.path_to_audio.endswith("/"): args.path_to_audio = args.path_to_audio[:-1] if not os.path.exists(args.path_to_audio): print "Path to audio '%s' not found" % args.path_to_audio sys.exit(-1) if args.path_to_features is None: if not os.path.exists("features"): os.mkdir("features") args.path_to_features = "features/"+args.collection_name if args.path_to_features.endswith("/"): args.path_to_features = args.path_to_features[:-1] if not os.path.exists(args.path_to_features[:args.path_to_features.rfind("/")]): print "Path to features '%s' not found" % args.path_to_features sys.exit(-1) print args extractor = FeatureExtractor(args.extractor) extractor.extract(args.path_to_audio, args.path_to_features, args.audio_filetype, args.replace_features)
origins = [] cameras = [] D4prev = np.array([0, 0, 0, 0]).reshape(4, 1) col_prev = np.array([0, 0, 0]).reshape(1, 3) q = Queue() mapa = Map() p = Process(target=draw_process, args=(q,)) p.start() ### INIT FIRST FRAME im = cv2.imread(dir + im_list[0]) Fr = Frame(im) Fr.pose = np.eye(4) # im = undistort(im) Fr.add_feature(feate.extract(Fr.im)) mapa.append_frame(Fr) cameras.append(np.eye(4)) ##### Process another frame for it in range(1, len(im_list)): # for imname in im_list: im = cv2.imread(dir + im_list[it]) Fr = Frame(im) # im = undistort(im) Fr.add_feature(feate.extract(Fr.im)) mapa.append_frame(Fr) idx1, idx2, D4, pts2 = feate.estimate_pose(*(mapa.get_two_back_frame())) D4 = mapa.frames[-2].pose @ D4.T
if __name__ == "__main__": dir = "/home/sviat/Documents/Datasets/kitti/2011_09_26/2011_09_26_drive_0009_sync/image_00/data/" # dir = "/home/sviatoslavpovod/Downloads/mav0/cam0/data/" im_list = sorted(os.listdir(dir)) feate = FeatureExtractor(K) f1 = 0 RTprev = np.eye(4) origins = [] D4prev = np.array([0, 0, 0]).reshape(3, 1) im_prev = 0 while True: for imname in im_list: im = cv2.imread(dir + imname) f2 = feate.extract(im) if f1 != 0: ## 2D points on image pts2, pts1 = feate.matches_frame(f1, f2) ## R, T between cameras R, T = feate.getRT(pts1, pts2) ## 3D points D4 = feate.get3D(R, T, pts1.T, pts2.T).T D4 = D4[:, :3] / D4[:, 3:4] mask = D4[:, 2] > 0.05 D4 = D4[mask]
if not os.path.exists(args.extractor): print "Path to extractor '%s' not found" % args.extractor sys.exit(-1) if args.path_to_audio is None: args.path_to_audio = "audio/" + args.collection_name if args.path_to_audio.endswith("/"): args.path_to_audio = args.path_to_audio[:-1] if not os.path.exists(args.path_to_audio): print "Path to audio '%s' not found" % args.path_to_audio sys.exit(-1) if args.path_to_features is None: if not os.path.exists("features"): os.mkdir("features") args.path_to_features = "features/" + args.collection_name if args.path_to_features.endswith("/"): args.path_to_features = args.path_to_features[:-1] if not os.path.exists( args.path_to_features[:args.path_to_features.rfind("/")]): print "Path to features '%s' not found" % args.path_to_features sys.exit(-1) print args extractor = FeatureExtractor(args.extractor) extractor.extract(args.path_to_audio, args.path_to_features, args.audio_filetype, args.replace_features)