def perform_clustering(cluster_task_id,test=False): clusters_dir = "{}/clusters/".format(settings.MEDIA_ROOT) if not os.path.isdir(clusters_dir): os.mkdir(clusters_dir) dc = Clusters.objects.get(pk=cluster_task_id) fnames = [] for ipk in dc.included_index_entries_pk: k = IndexEntries.objects.get(pk=ipk) fnames.append("{}/{}/indexes/{}".format(settings.MEDIA_ROOT, k.video.pk, k.features_file_name)) cluster_proto_filename = "{}{}.proto".format(clusters_dir,dc.pk) c = clustering.Clustering(fnames, 64,cluster_proto_filename,m=dc.m,v=dc.v,sub=dc.sub,test_mode=test) c.cluster() for e in c.entries: cc = ClusterCodes() cc.video_id = e['video_primary_key'] if 'detection_primary_key' in e: cc.detection_id = e['detection_primary_key'] cc.frame_id = Detection.objects.get(pk=cc.detection_id).frame_id else: cc.frame_id = e['frame_primary_key'] cc.clusters = dc cc.coarse = e['coarse'] cc.fine = e['fine'] cc.coarse_text = " ".join(map(str,e['coarse'])) cc.fine_text = " ".join(map(str,e['fine'])) cc.save() c.save()
def load_clusterer(self, algorithm): dc = Clusters.objects.all().filter(completed=True, indexer_algorithm=algorithm).last() if dc: model_file_name = "{}/clusters/{}.proto".format(settings.MEDIA_ROOT, dc.pk) IndexerTask._clusterer[algorithm] = clustering.Clustering(fnames=[], m=None, v=None, sub=None,n_components=None,model_proto_filename=model_file_name, dc=dc) logging.warning("loading clusterer {}".format(model_file_name)) IndexerTask._clusterer[algorithm].load() else: logging.warning("No clusterer found switching to exact search for {}".format(algorithm))
def perform_clustering(cluster_task_id, test=False): start = TEvent.objects.get(pk=cluster_task_id) if celery_40_bug_hack(start): return 0 start.task_id = perform_clustering.request.id start.started = True start.ts = datetime.now() start.operation = perform_clustering.name start.save() start_time = time.time() clusters_dir = "{}/clusters/".format(settings.MEDIA_ROOT) if not os.path.isdir(clusters_dir): os.mkdir(clusters_dir) dc = start.clustering fnames = [] for ipk in dc.included_index_entries_pk: k = IndexEntries.objects.get(pk=ipk) fnames.append("{}/{}/indexes/{}".format(settings.MEDIA_ROOT, k.video.pk, k.features_file_name)) cluster_proto_filename = "{}{}.proto".format(clusters_dir, dc.pk) c = clustering.Clustering(fnames, dc.components, cluster_proto_filename, m=dc.m, v=dc.v, sub=dc.sub, test_mode=test) c.cluster() cluster_codes = [] for e in c.entries: cc = ClusterCodes() cc.video_id = e['video_primary_key'] if 'detection_primary_key' in e: cc.detection_id = e['detection_primary_key'] cc.frame_id = Region.objects.get(pk=cc.detection_id).frame_id else: cc.frame_id = e['frame_primary_key'] cc.clusters = dc cc.coarse = e['coarse'] cc.fine = e['fine'] cc.coarse_text = " ".join(map(str, e['coarse'])) cc.fine_text = " ".join(map(str, e['fine'])) cc.searcher_index = e['index'] cluster_codes.append(cc) ClusterCodes.objects.bulk_create(cluster_codes) c.save() dc.completed = True dc.save() start.completed = True start.seconds = time.time() - start_time start.save()
def perform_clustering(cluster_task_id): dc = Clusters.objects.get(pk=cluster_task_id) fname = "{}/{}/indexes/{}".format(settings.MEDIA_ROOT,dc.video.pk,dc.index_entries.features_file_name) c = clustering.Clustering(fname,64) c.cluster()