Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas committed May 30, 2024
1 parent 36fe6c1 commit 259ce86
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 305 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ FL_AD_CLAP.zip
wandb/
data/ucf/clusters
data/XD/clusters
datasetsplits/
datasetsplits/
drafts/
Binary file modified data/utils/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified data/utils/__pycache__/constants.cpython-311.pyc
Binary file not shown.
Binary file modified data/utils/__pycache__/datasets.cpython-311.pyc
Binary file not shown.
51 changes: 25 additions & 26 deletions data/utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from argparse import Namespace
from pathlib import Path
from typing import List, Type, Dict
import wandb
# import wandb
import torch
import numpy as np
import torchvision
Expand Down Expand Up @@ -707,24 +707,24 @@ def C2FPL_client(train_data,args, client_partition,client_video_num_partition,
# break
# print(f"Client {client_id} has {n_num} normal videon and {a_num} abnormal videos \n Total number of videos of {n_num + a_num}")

params = []
top_k = 30
for i in range(len(new_repr)):
entropy = 0
# params = []
# top_k = 30
# for i in range(len(new_repr)): # entropy and var diff
# entropy = 0

param_1 = get_matrix(new_repr[i]) # l2 norm
mu, var = estimate_gauss(param_1) # mean and variance of l2 norm
# param_1 = get_matrix(new_repr[i]) # l2 norm
# mu, var = estimate_gauss(param_1) # mean and variance of l2 norm

l2_diff = np.diff(param_1, n=1) # max diff
var_diff = np.var(l2_diff) # variance of max diff
max_diff = np.max(np.diff(param_1, n=1))
param_2 = covariance_mat(new_repr[i])
param_2 = np.where(param_2 == 0, 0.000000001,param_2)
for i in np.diagonal(param_2):
entropy += -(i * np.log(i))
# l2_diff = np.diff(param_1, n=1) # max diff
# var_diff = np.var(l2_diff) # variance of max diff
# max_diff = np.max(np.diff(param_1, n=1))
# param_2 = covariance_mat(new_repr[i])
# param_2 = np.where(param_2 == 0, 0.000000001,param_2)
# for i in np.diagonal(param_2):
# entropy += -(i * np.log(i))


params.append((max_diff, entropy))
# params.append((max_diff, entropy))


# params = []
Expand Down Expand Up @@ -759,15 +759,15 @@ def C2FPL_client(train_data,args, client_partition,client_video_num_partition,
# params.append(np.diagonal(param_2[:top_k, :top_k]))


# params = []
params = []

# for i in range(len(new_repr)):
for i in range(len(new_repr)):

# param = get_matrix(new_repr[i])
# mu, var = estimate_gauss(param)
param = get_matrix(new_repr[i])
mu, var = estimate_gauss(param)


# params.append((mu,var,))
params.append((mu,var,))



Expand Down Expand Up @@ -918,7 +918,7 @@ def C2FPL_client(train_data,args, client_partition,client_video_num_partition,

# print(df)

wandb.log({f"Client {client_id} Clustering ACC": wandb.Table(dataframe=df)})
# wandb.log({f"Client {client_id} Clustering ACC": wandb.Table(dataframe=df)})



Expand Down Expand Up @@ -1332,7 +1332,6 @@ def C2FPL_client_eta(train_data,args, client_partition,client_video_num_partitio




def pl_refining(args, confidance_scores, total_clients):
df_1 = pd.DataFrame(columns=['Class','max_confidance_score', 'mean_confidance_scores'])
try:
Expand Down Expand Up @@ -1384,7 +1383,7 @@ def pl_refining(args, confidance_scores, total_clients):
df_1.loc[idel, 'max_confidance_score'] = np.max(confidance_scores[from_id:to_id])
df_1.loc[idel, 'mean_confidance_scores'] = np.mean(confidance_scores[from_id:to_id])

wandb.log({f"Videos Confidance Scores": wandb.Table(dataframe=df_1)})
# wandb.log({f"Videos Confidance Scores": wandb.Table(dataframe=df_1)})



Expand Down Expand Up @@ -1436,7 +1435,7 @@ def pl_refining(args, confidance_scores, total_clients):


from itertools import islice
# dict(islice(abnormal_list.items(), 1, int(0.8*len(abnormal_list))))

def gmm_PL(args, total_clients, gmm_params, vids_num):

all_abnormal = {}
Expand Down Expand Up @@ -1560,7 +1559,7 @@ def __init__(self,args, transform=None, test_mode=False):
raise FileNotFoundError(f"Please partition {args.dataset} first.")

if args.dataset == 'ucf':
self.no_of_vids = 1317 #1608
self.no_of_vids = 1608 #1608
else:
self.no_of_vids = 3954

Expand All @@ -1574,7 +1573,7 @@ def __init__(self,args, transform=None, test_mode=False):


if args.dataset == 'ucf':
self.con_all = np.load('data/datasets/concat_UCF_V2.npy')[85902:]
self.con_all = np.load('data/datasets/concat_UCF_V2.npy')
if args.dataset == 'XD':
self.con_all = np.load("data/datasets/concat_XD.npy")
print('self.con_all shape:',self.con_all.shape)
Expand Down
381 changes: 155 additions & 226 deletions drafts/paper_plot.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 259ce86

Please sign in to comment.