Hi Marsggbo!
Interesting results …



 marsggbo:

…
I’ve tried WeightedSampler, but it seems not work. The results comparison is as follows:


Before use WeightedSampler
Accuracy on training set: top1/5 = 53% / 82%
Accuracy on testing set: top1/5 = 48% / 77%


After use WeightedSampler
Accuracy on training set: top1/5 = 67% / 90%
Accuracy on testing set: top1/5 = 30% / 69%


I also tried WeightedLoss, the result is:
Accuracy on training set: top1/5 = 21% / 53%
Accuracy on testing set: top1/5 = 22% / 53%


So what else should I do now to further improve the performance of my model? Thanks again!


A quick comment:
With WeightedSampler your training accuracy went up, but
your test accuracy went down.  This suggests that you may be
over-fitting.  I might guess that you are over-fitting your B-class
images, as you have relatively few of them and are presumably
reusing each one in your training more often.
You don’t say precisely how you are reweighting (neither with
WeightedSampler nor with WeightedLoss).  If you are fully
reweighting (so that each batch has, on average, the same
number of A-class and B-class images), you might want to
try only partially reweighting.  (If you use WeightedSampler,
but use a flat weight so that you don’t actually reweight, you
should get the same result as not using WeightedSampler
at all.)  It’s possible (but no guarantee) that somewhere in
between flat weighting and full reweighting you get improved
results on your test accuracy as well as your training accuracy.
It’s worth a try, I think.  (The same comments also apply to only
partially reweighting WeightedLoss.)
If that doesn’t help, it may be a consequence of having relatively
few B-class images.  If so, you might consider using a network
with fewer layers / parameters in the hope it reduces the tendency
to over-fit.  (Or train less or use smaller / bigger batches, etc.)
Best.
K. Frank