def main(argv): try: opts, args = getopt.getopt(argv,"frt") except getopt.GetoptError: print('pptGen.py -option where option [-f|-r|-t] f=read and extract features r=read existent features t=test') sys.exit(2) (pap, pres) = readData2() for opt, arg in opts: if opt == '-f': featureExtractor = FeatureExtractor(pap, pres) features = featureExtractor.extractFeatures() pickle.dump(features, open(feature_file, 'wb')) scores = featureExtractor.getImportanceMetrics() pickle.dump(scores, open(score_file, 'wb')) print(features) print(scores) if opt == '-r': features = pickle.load(open( feature_file, "rb" )) scores = pickle.load(open(score_file, "rb"))
models = torch.load(os.path.join(output_dir, 'regressor_detector')) stats = torch.load(os.path.join(output_dir, 'stats_detector')) # Detector Region Classifier initialization classifier = falkon.FALKONWrapper(cfg_path=cfg_online_path) regionClassifier = ocr.OnlineRegionClassifier(classifier, None, None, stats, cfg_path=cfg_online_path) region_refiner = RegionRefiner(cfg_online_path) else: # Extract detector features for the train set if not args.save_detector_features and not args.load_detector_features: negatives, positives, COXY = feature_extractor.extractFeatures( is_train=True, output_dir=output_dir, save_features=args.save_detector_features) else: if args.save_detector_features: feature_extractor.extractFeatures( is_train=True, output_dir=output_dir, save_features=args.save_detector_features) positives, negatives = load_features_classifier( features_dir=os.path.join(output_dir, 'features_detector')) stats = computeFeatStatistics_torch(positives, negatives, features_dim=positives[0].size()[1], cpu_tensor=args.CPU) # Detector Region Classifier initialization
if not os.path.exists(output_dir): os.mkdir(output_dir) # Initialize feature extractor feature_extractor = FeatureExtractor(cfg_target_task, train_in_cpu=args.CPU) # Load detector models if requested, else train them if args.load_detector_models: model = torch.load(os.path.join(output_dir, 'classifier_detector')) models = torch.load(os.path.join(output_dir, 'regressor_detector')) stats = torch.load(os.path.join(output_dir, 'stats_detector')) else: # Extract detector features for the train set if not args.save_detector_features and not args.load_detector_features: negatives, positives, COXY, negatives_segmentation, positives_segmentation = feature_extractor.extractFeatures(is_train=True, output_dir=output_dir, save_features=args.save_detector_features, extract_features_segmentation=True, use_only_gt_positives_detection=args.use_only_gt_positives_detection) del feature_extractor torch.cuda.empty_cache() # Detector Region Refiner initialization region_refiner = RegionRefiner(cfg_online_path) if not args.normalize_features_regressor_detector: models = region_refiner.trainRegionRefiner(COXY, output_dir=output_dir) del region_refiner torch.cuda.empty_cache() if not args.use_only_gt_positives_detection: positives = load_positives_from_COXY(COXY) # Delete already used data