Code Monkey home page Code Monkey logo

Comments (5)

yikaiw avatar yikaiw commented on August 18, 2024 1

Hi, for semantic segmentation, the sparsity constraint is implemented at:
(1) different (disjoint) sub-parts,

if param.requires_grad and name.endswith('weight') and 'bn2' in name:
if len(slim_params) % 2 == 0:
slim_params.append(param[:len(param) // 2])
else:
slim_params.append(param[len(param) // 2:])

(2) adding the loss of the sparsity constraint,
L1_norm = sum([L1_penalty(m).cuda() for m in slim_params])
loss += lamda * L1_norm # this is actually counted for len(outputs) times

For image-to-image translation, the sparsity constraint is implemented at:
(1) different (disjoint) sub-parts,

slim_params, insnorm_params = [], []
for name, param in G.named_parameters():
if param.requires_grad and name.endswith('weight') and 'insnorm_conv' in name:
insnorm_params.append(param)
if len(slim_params) % 2 == 0:
slim_params.append(param[:len(param) // 2])
else:
slim_params.append(param[len(param) // 2:])

(2) adding the loss of the sparsity constraint,
# L1 loss
l1_loss = params.gama * sum([L1_loss(gen_image, y_) for gen_image in gen_images])
if params.lamda > 0:
slim_loss = params.lamda * sum([slim_penalty(m).cuda() for m in slim_params])
else:
slim_loss = 0

from cen.

hljeong avatar hljeong commented on August 18, 2024

Thank you for your reply! However I am still confused as to where the sparsity constraint in terms of channel exchanging is implemented, as the sections of code you referenced seem to be applying the sparsity constraint to the loss calculation.

I am mainly confused about

x1[:, bn1 >= bn_threshold] = x[0][:, bn1 >= bn_threshold]
x1[:, bn1 < bn_threshold] = x[1][:, bn1 < bn_threshold]
x2[:, bn2 >= bn_threshold] = x[1][:, bn2 >= bn_threshold]
x2[:, bn2 < bn_threshold] = x[0][:, bn2 < bn_threshold]

which seems to exchange channels within all of x[0] and x[1], instead of disjoint sub-parts of them.

from cen.

yikaiw avatar yikaiw commented on August 18, 2024

Hi, take semantic segmentation as an example:
We apply the sparsity constraints on disjoint sub-parts of BN scaling factors in,

if param.requires_grad and name.endswith('weight') and 'bn2' in name:
if len(slim_params) % 2 == 0:
slim_params.append(param[:len(param) // 2])
else:
slim_params.append(param[len(param) // 2:])

In the case of two modalities, we divide channels into two disjoint sub-parts, which is implemented by adding param[:len(param) // 2 and param[len(param) // 2:] to slim_params. Followed up by the sparsity loss on slim_params, which means only the sub-parts in slim_params are constrained by L1.

We find if a channel is out of the sparsity constraints (L1), its BN scaling factor can be hardly lower than the small threshold during training. Therefore we check the criteria for channel exchanging directly on the whole channels,

x1[:, bn1 >= bn_threshold] = x[0][:, bn1 >= bn_threshold]
x1[:, bn1 < bn_threshold] = x[1][:, bn1 < bn_threshold]
x2[:, bn2 >= bn_threshold] = x[1][:, bn2 >= bn_threshold]
x2[:, bn2 < bn_threshold] = x[0][:, bn2 < bn_threshold]

Since constraining half (disjoint sub-parts) of the channels is already implemented in main.py, checking the exchanging criteria on the whole channels is almost equivalent to disjoint sub-parts.

from cen.

hljeong avatar hljeong commented on August 18, 2024

That makes sense. Thank you for your detailed explanation!

from cen.

rginjapan avatar rginjapan commented on August 18, 2024

@yikaiw 你好 (1) 我不是特别理解用L1norm来惩罚 scale factor 在loss function 的意义,这一项在loss function里不就是让 scale factor 越来越小么 简单的来说。能不能稍微解释一下呢, 谢谢🙏
(2)这里的certain portion 就是disjoint 的那部分的意思是么?
截屏2022-11-04 17 55 21
截屏2022-11-04 17 55 55

from cen.

Related Issues (17)

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.