Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem on calculating the entropy #2

Open
hubaak opened this issue Mar 20, 2024 · 6 comments
Open

Problem on calculating the entropy #2

hubaak opened this issue Mar 20, 2024 · 6 comments

Comments

@hubaak
Copy link

hubaak commented Mar 20, 2024

Thanks for your exciting work in dealing with the problem of multimodal imbalance. However, I met some troubles when running the code.
In main.py, the code for calculating entropy is shown below:

def calculate_entropy(output):
    probabilities = F.softmax(output, dim=0)
    # probabilities = F.softmax(output, dim=1)
    log_probabilities = torch.log(probabilities)
    entropy = -torch.sum(probabilities * log_probabilities)
    return entropy

The size of the output is [B, N] (B for batch and N for the numbers of categories).
According to the Equation (8) in the paper, the correct code to get entropy should be:

def calculate_entropy(output):
    # probabilities = F.softmax(output, dim=0)
    probabilities = F.softmax(output, dim=1) # Softmax through categories
    log_probabilities = torch.log(probabilities)
    entropy = -torch.sum(probabilities * log_probabilities, dim=-1) # If you don't add "dim=-1" then you sum up the entropy in the whole batch
    return entropy

What makes a difference here is entropy should be calculated for each sample, but not be summed up in a batch.

Oh! By the way, I think Equation (8) looks a little bit odd as 'm' shows up on the left side of the equation and serves as indices of the 'max' operation.

Equation 8 in the paper

@LittlePoolSpirit
Copy link

I think you're right. When I run -- dynamic, the effect is even worse than the fixed fusion method.

@Cecile-hi
Copy link
Owner

Hi @hubaak, yeah, it seems we may have some mistakes on entropy calculation, we will do some carefully check on it and make some correction.

In addition, thank you for your kind suggestion for the eq.8. In this eq, we want to use "m" to represent modality, however I think you are right, it looks a bit ambiguous, I will discuss this will my Prof and make any essential correction in the camera-ready paper.

@Cecile-hi
Copy link
Owner

Hi @LittlePoolSpirit, I think decreasing the eval batch szie may make some effect (e.g. --batch_size 1).
For example, using the released ckpt
With Fixed weight:

python main.py --ckpt_path best_model_of_dataset_CREMAD_Normal_alpha_0.3_optimizer_sgd_modulate_starts_0_ends_50_epoch_91_acc_0.7768817204301075.pth --gs_flag --dataset CREMAD --batch_size 1 --lorb base --av_alpha 0.55

We have: Accuracy: 0.7768817204301075, accuracy_a: 0.5981182795698925, accuracy_v: 0.668010752688172

--dyanmic (with the modification by @hubaak )

python main.py --ckpt_path best_model_of_dataset_CREMAD_Normal_alpha_0.3_optimizer_sgd_modulate_starts_0_ends_50_epoch_91_acc_0.7768817204301075.pth --gs_flag --dataset CREMAD --batch_size 1 --lorb base --dynamic

We have: Accuracy: 0.7876344086021505, accuracy_a: 0.5981182795698925, accuracy_v: 0.668010752688172

@thinking024
Copy link

Good idea, I met the same problem, too.

@ggamaz
Copy link

ggamaz commented Oct 18, 2024

i just find that the eq.8 can be simplifed as follow:
image
it just may be a softmax as follow:
image

@hubaak
Copy link
Author

hubaak commented Oct 21, 2024

i just find that the eq.8 can be simplifed as follow: image it just may be a softmax as follow: image

Yeah, they simply weight the outputs of models with their minus entropy after softmax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants