CKA-Centered-Kernel-Alignment icon indicating copy to clipboard operation
CKA-Centered-Kernel-Alignment copied to clipboard

size issue

Open Yhyyy-hhu opened this issue 1 year ago • 5 comments

hi guys, Is it true that the CKA could only calculate matrix with 2 size? one for BS, one for another arbitrary one? if so, it seems not suitable to compare among pictures. looking for answer and many thanks

Yhyyy-hhu avatar Mar 08 '23 05:03 Yhyyy-hhu

I am not sure if I understood the question. I apologize if I get it wrong. CKA will compare 2 Symmetric Positive Semi-Definite Matrices of Size KxK each. I didn't quite get the part where you refer to comparison between pictures.

23Uday avatar Mar 08 '23 05:03 23Uday

I am not sure if I understood the question. I apologize if I get it wrong. CKA will compare 2 Symmetric Positive Semi-Definite Matrices of Size KxK each. I didn't quite get the part where you refer to comparison between pictures.

Thanks for your reply. Let's assume the output of a layer is A with size (BS, C, K, K). The function of kernal_CKA(A, A) turns to be wrong. So I guess it could only deal with matrix of size 2. I suppose this is also the reason the author takes the average of output of (1000,16,16,64) in axis 1 and 2, and thereafter get output of size (1000, 64) in line [25]

Yhyyy-hhu avatar Mar 08 '23 07:03 Yhyyy-hhu

Yes, it can only deal with matrices and not tensors. If I may offer a suggestion/guess, I think what you want to do is to take the output of layer with size (BS,C,K,K) and convert it to X.shape = (BS,CKK). Then compute S_1 = XX.T, this will yield a BS x BS sized matrix. You can repeat this process for another layer Y => (BS, C ,K, K)-> (BS,CKK) and compute S_2 = YY.T and compute CKA(S_1,S_2). This is roughly how I do it.

23Uday avatar Mar 08 '23 07:03 23Uday

Many thanks dude! I do appreciate your help!

Yhyyy-hhu avatar Mar 08 '23 08:03 Yhyyy-hhu

Glad to help.

23Uday avatar Mar 08 '23 08:03 23Uday