BSc project of Parham Saremi. The goal of the project was to detect the geographical region of the food using textual and visual features extracted from recipes and ingredients of the food.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bypass_bn.py 478B

1234567891011121314151617
  1. import torch
  2. import torch.nn as nn
  3. def disable_running_stats(model):
  4. def _disable(module):
  5. if isinstance(module, nn.BatchNorm2d):
  6. module.backup_momentum = module.momentum
  7. module.momentum = 0
  8. model.apply(_disable)
  9. def enable_running_stats(model):
  10. def _enable(module):
  11. if isinstance(module, nn.BatchNorm2d) and hasattr(module, "backup_momentum"):
  12. module.momentum = module.backup_momentum
  13. model.apply(_enable)