You may be on an old version of torchvision or torch, can you make sure you’re on the latest of both? (or use the nightly if there are still errors)
Your code works fine for me after applying the following diff:
diff --git a/test.py b/test.py
index e305823abd..a96eb93829 100644
--- a/test.py
+++ b/test.py
@@ -208,21 +208,20 @@ class ResnetEncoder(nn.Module):
             self.num_ch_enc[1:] *= 4
 
     def forward(self, input_image):
-        self.features = []
+        features = []
         x = (input_image - 0.45) / 0.225
         x = self.encoder.conv1(x)
         x = self.encoder.bn1(x)
-        self.features.append(self.encoder.relu(x))
-        self.features.append(self.encoder.layer1(self.encoder.maxpool(self.features[-1])))
-        self.features.append(self.encoder.layer2(self.features[-1]))
-        self.features.append(self.encoder.layer3(self.features[-1]))
-        self.features.append(self.encoder.layer4(self.features[-1]))
+        features.append(self.encoder.relu(x))
+        features.append(self.encoder.layer1(self.encoder.maxpool(features[-1])))
+        features.append(self.encoder.layer2(features[-1]))
+        features.append(self.encoder.layer3(features[-1]))
+        features.append(self.encoder.layer4(features[-1]))
 
-        return self.features
+        return features
 
 encoder = ResnetEncoder(18, True )
-example = torch.rand(1, 3, 640, 192)
-traced_script_module_encoder = torch.jit.trace(encoder.__getattr__('encoder'), example )
+traced_script_module = torch.jit.script(encoder)
 traced_script_module.save('encoder_new.pt')
 torch.jit.load('encoder_new.pt')

This is necessary since in TorchScript you can’t add new attributes to self outside of __init__ (you can only mutate existing attributes), but here it looks like features wasn’t being used outside of forward anyways.