def main(): selectors = [ FPSReductionKS(n=3), MaxHistDiffKS(frames_per_window=1), ] extractors = [ ColorLayoutFE(), AutoEncoderFE(dummy=True), ] indexes = [ LinearIndex(dummy=True), KDTreeIndex(dummy=True, trees=5), SGHIndex(dummy=True, projections=10), ] lshs = [ LSHIndex(dummy=True, projections=5, tables=10), # color layout LSHIndex(dummy=True, projections=3, tables=10), # auto encoder ] for selector in selectors: read_selection_log(selector, extractors) for extractor in extractors: read_extraction_log(extractor, selectors) for index in indexes: read_index_logs(selectors, extractors, index) for i in range(len(lshs)): read_index_logs(selectors, [extractors[i]], lshs[i]) read_detection_log() return
def main(): selector = FPSReductionKS(n=3) extractors = [ ColorLayoutFE(), AutoEncoderFE.load_autoencoder(model_name='../features/model'), ] for extractor in extractors: tags, features = group_features(selector=selector, extractor=extractor) x = range(features.shape[1]) mean = np.mean(features, axis=0) std = np.std(features, axis=0) mins = np.min(features, axis=0) maxs = np.max(features, axis=0) plt.figure() plt.title(f'{selector.name()} - {extractor.name()}') plt.errorbar(x, mean, std, fmt='.b', ecolor='r', capsize=3) plt.plot(x, maxs, 'g') plt.plot(x, mins, 'y') plt.legend([ 'max', 'min', ]) plt.xlabel('features') plt.ylabel('value') plt.show() return
def main(): selectors = [ FPSReductionKS(n=3), # MaxHistDiffKS(frames_per_window=1), ] extractors = [ ColorLayoutFE(), AutoEncoderFE(dummy=True, model_name='model'), ] indexes = [ # LinearIndex(dummy=True, k=100), KDTreeIndex(dummy=True, trees=5, k=100), # SGHIndex(dummy=True, projections=14, tables=2, k=100), # LSHIndex(dummy=True, projections=14, k=100), ] for selector in selectors: for extractor in extractors: for index in indexes: find_copies( video_name='385', selector=selector, extractor=extractor, index=index, ) return
def main(): numpy.random.seed(1209) load = False # input shape shape = (64, 64, 3) # select keyframes and shuffle selector = FPSReductionKS(n=1) videos = ['003', '071', '118', '209', '258', '385', '437'] videos_path = get_videos_dir() frames, _, _ = selector.select_keyframes(f'{videos_path}/{videos[0]}.mp4') for video in videos[1:]: frames_2, _, _ = selector.select_keyframes( f'{videos_path}/{video}.mp4') frames = numpy.concatenate([frames, frames_2]) numpy.random.shuffle(frames) if load: autoencoder = AutoEncoderFE.load_autoencoder(model_name='model') shape = autoencoder.input_shape print(f'input size: {shape}') else: # best: tanh-tanh, second: tanh-relu autoencoder = AutoEncoderFE(input_shape=shape, cells=4, convs=2, activation='tanh', output_activation='tanh', model_name='model2') autoencoder.train(frames, epochs=50) autoencoder.save() print(f'descriptor size: {autoencoder.output_size}') autoencoder.test(frames[:100]) return
def main(): videos = ['417', '143', '215', '385', '178', '119-120', ] selectors = [ FPSReductionKS(n=3), MaxHistDiffKS(frames_per_window=1), ] extractors = [ ColorLayoutFE(), AutoEncoderFE(dummy=True), ] indexes = [ LinearIndex(dummy=True), KDTreeIndex(dummy=True, trees=5), SGHIndex(dummy=True, projections=10), LSHIndex(dummy=True, projections=5, tables=10), # color layout LSHIndex(dummy=True, projections=3, tables=10), # auto encoder ] datasets = [ (selectors[0], extractors[0], indexes[0],), # linear # (selectors[0], extractors[0], indexes[1],), # kdtree # (selectors[0], extractors[0], indexes[2],), # sgh # (selectors[0], extractors[0], indexes[3],), # lsh # (selectors[0], extractors[1], indexes[0],), # linear # (selectors[0], extractors[1], indexes[1],), # kdtree # (selectors[0], extractors[1], indexes[2],), # sgh # (selectors[0], extractors[1], indexes[4],), # lsh # (selectors[1], extractors[0], indexes[1],), # kdtree # (selectors[1], extractors[0], indexes[2],), # sgh # (selectors[1], extractors[0], indexes[3],), # lsh # (selectors[1], extractors[1], indexes[1],), # kdtree # (selectors[1], extractors[1], indexes[2],), # sgh # (selectors[1], extractors[1], indexes[4],), # lsh ] for video in videos: for selector, extractor, index in datasets: evaluate_duplicates( video_name=video, selector=selector, extractor=extractor, index=index, ) return
def main(): selectors = [ FPSReductionKS(n=3), MaxHistDiffKS(frames_per_window=1), ] extractors = [ ColorLayoutFE(), AutoEncoderFE.load_autoencoder(model_name='features/model'), ] for selector in selectors: for extractor in extractors: extract_features_videos(selector=selector, extractor=extractor, force=True) return
def main(): np.random.seed(1209) videos = [ '119-120', '143', '178', '215', '385', '417', ] # ['190', '227', ] k = 100 selectors = [ MaxHistDiffKS(frames_per_window=1), FPSReductionKS(n=3), ] extractors = [ ColorLayoutFE(), # AutoEncoderFE.load_autoencoder(model_name='features/model'), ] indexes = [ [LinearIndex, {}], [KDTreeIndex, { 'trees': 5, 'checks': 1000 }], [SGHIndex, { 'projections': 10, 'training_split': 0.3 }], [LSHIndex, { 'projections': 5, 'tables': 10, 'bin_width': 20 }], # for color layout # [LSHIndex, {'projections': 3, 'tables': 10, 'bin_width': 20}], # for autoencoder ] for selector in selectors: for extractor in extractors: print('\n') all_tags, all_features = group_features(selector=selector, extractor=extractor) print(f'loaded {all_features.shape[0]:,} features') for index_class, kwargs in indexes: print(f'\nstarting index construction') index = index_class(data=all_features, labels=all_tags, k=k, **kwargs) print( f'{index.name()} construction took {index.build_time:.1f} seconds\n' ) try: index.engine.analize_storage() except: pass neighbours_path = get_neighbours_dir(selector=selector, extractor=extractor, index=index) if not os.path.isdir(neighbours_path): os.makedirs(neighbours_path) log_path = f'{neighbours_path}/constructions.txt' log_persistent( f'{index.name()}\t{index.build_time:.2f}\t{all_features.shape[0]}\n', log_path=log_path) for video_name in videos: nearest_neighbours(video_name=video_name, selector=selector, extractor=extractor, index=index, analize=True, force=True) return
def add_timestamp(frames, timestamps): for i in range(len(frames)): cv2.putText(frames[i], f'{timestamps[i]:.2f}', (10, 30), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), thickness=5) cv2.putText(frames[i], f'{timestamps[i]:.2f}', (10, 30), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), thickness=2) if __name__ == '__main__': from keyframes import FPSReductionKS, MaxHistDiffKS chapter = '../../videos/Shippuden_low/178.mp4' selector1 = FPSReductionKS() keyframes1, timestamps1, _ = selector1.select_keyframes(chapter) selector2 = MaxHistDiffKS(frames_per_window=1) keyframes2, timestamps2, _ = selector2.select_keyframes(chapter) print(len(keyframes1), len(keyframes2), int(timestamps1[-1])) keyframes1 = resize_frames(keyframes1) add_timestamp(keyframes1, timestamps1) keyframes2 = resize_frames(keyframes2) add_timestamp(keyframes2, timestamps2) # show keyframes i1 = 0