Giter Site home page Giter Site logo

Comments (2)

TFboys-lzz avatar TFboys-lzz commented on May 24, 2024

Sorry I didn't see it until now.
For calculating category centers, you first need pretrain the model on the source dataset,
and then you can calculate the category center by

def update_class_center_iter(cla_src_feas,batch_src_labels,class_center_feas,m):
'''
batch_src_feas : n*c*h*w
barch_src_labels: n*h*w
'''
batch_src_feas = cla_src_feas.detach()
batch_src_labels = batch_src_labels.cuda()
n,c,fea_h,fea_w = batch_src_feas.size()
batch_y_downsample = label_downsample(batch_src_labels, fea_h, fea_w) # n*fea_h*fea_w
batch_y_downsample = batch_y_downsample.unsqueeze(1) # n*1*fea_h*fea_w
batch_class_center_fea_list = []
for i in range(5):
fea_mask = torch.eq(batch_y_downsample,i).float().cuda() #n*1*fea_h*fea_w
class_feas = batch_src_feas * fea_mask # n*c*fea_h*fea_w
class_fea_sum = torch.sum(class_feas, [0, 2, 3]) # c
class_num = torch.sum(fea_mask, [0, 1, 2, 3])
if class_num == 0:
batch_class_center_fea = class_center_feas[i,:].detach()
else:
batch_class_center_fea = class_fea_sum/class_num
batch_class_center_fea = batch_class_center_fea.unsqueeze(0) # 1 * c
batch_class_center_fea_list.append(batch_class_center_fea)
batch_class_center_feas = torch.cat(batch_class_center_fea_list,dim=0) # n_class * c
class_center_feas = m * class_center_feas + (1-m) * batch_class_center_feas
return class_center_feas

from mpscl.

dongdongtong avatar dongdongtong commented on May 24, 2024

Sovled. Thanks for your kindly reply.

from mpscl.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.