Hi,
I met a strange bug:
My model: EfficientDet-D4 (following this repo)
While training the model, I use model.train()
, then change it to model.eval()
in validate step and it worked normally.
However, in the test phase, my code is:
from efficientdet.model import Classifier
model = EfficientDetBackbone(num_classes=len(params.obj_list), compound_coef=4,
ratios=eval(params.anchors_ratios), scales=eval(params.anchors_scales))
model.backbone_net.model._conv_stem.conv = nn.Conv2d(4, 48, kernel_size=(3, 3), stride=(2, 2), bias=False)
model.classifier.header.pointwise_conv.conv = nn.Conv2d(224, 9, kernel_size=(1, 1), stride=(1, 1))
model.classifier = Classifier(in_channels=model.fpn_num_filters[4], num_anchors=model.num_anchors,
num_classes=1,
num_layers=model.box_class_repeats[4],
pyramid_levels=model.pyramid_levels[4])
model.load_state_dict(torch.load(weights_path),strict=False)
model.requires_grad_(False)
model.eval()
with torch.no_grad():
for iter, data in enumerate(test_generator):
imgs = data['img']
_, regression, classification, anchors = model(imgs)
The result was really bad, it always returned the bounding boxes in the corner of the image, but when I commented out the line model.eval()
, the result was really good. Any idea why is it?