def evm_train_process(classes_to_process, feature_dic, args_evm, gpu, Q, done_event): with torch.no_grad(): evm_iterator_i = EVM_Training(classes_to_process, feature_dic, args_evm, gpu) evm_model = OrderedDict() n = 0 for evm in enumerate(evm_iterator_i): # evm_model[evm[1][1][0]] = evm[1][1][1] Q.put((evm[1][1][0], evm[1][1][1])) gc.collect() torch.cuda.empty_cache() torch.cuda.ipc_collect() done_event.wait() del evm return
for j, im_name in enumerate(image_names): label = feedback.get_label(im_name) if label > number_of_known_classes: class_to_process.add(label) feature_j = FV[j : (j + 1), :].clone().double() if label in features_dict_train: features_dict_train[label] = torch.cat((features_dict_train[label], feature_j), 0) else: nu = nu + 1 features_dict_train[label] = feature_j if len(class_to_process) > 0: class_to_process = sorted(list(class_to_process)) list_of_tuples = [0.0] * len(class_to_process) evm_iterator_i = EVM_Training(class_to_process, features_dict_train, args_evm_unknown, 0) evm_counter = 0 for evm in enumerate(evm_iterator_i): # label = evm[1][1][0] # mini_evm = evm[1][1][1] list_of_tuples[evm_counter] = (evm[1][1][0], evm[1][1][1]) evm_counter = evm_counter + 1 for j, class_number in enumerate(class_to_process): # evm is an OrderedDict assert list_of_tuples[j][0] == class_number evm_model[class_number] = list_of_tuples[j][1] del evm_iterator_i, evm gc.collect() torch.cuda.empty_cache()
to_be_delete = to_be_delete + index nu = nu + 1 class_number = int(nu + number_of_discovered_classes + number_of_known_classes) features_dict_incremental[class_number] = ( torch.from_numpy(np.array([FVs_residual[jjj] for jjj in index])) ).double() # .cuda() class_to_process.append(class_number) if ((len(class_to_process) > 0) and (number_of_discovered_classes > 0)) or ( len(class_to_process) > 2 ): list_of_tuples = [0.0] * len(class_to_process) evm_iterator_incremental = EVM_Training( class_to_process, features_dict_incremental, args_evm_incremental, 0 ) evm_counter = 0 for evm in enumerate(evm_iterator_incremental): # label = evm[1][1][0] # mini_evm = evm[1][1][1] list_of_tuples[evm_counter] = (evm[1][1][0], evm[1][1][1]) evm_counter = evm_counter + 1 for j, class_number in enumerate(class_to_process): # evm is an OrderedDict assert list_of_tuples[j][0] == class_number evm_model_incremental[class_number] = list_of_tuples[j][1] del evm_iterator_incremental, evm gc.collect()