title: TypeError: add(): argument 'other' (position 1) must be Tensor, not numpy.ndarray
body: <p>I am testing a ResNet-34 trained_model using Pytorch and fastai on a linux system with the latest anaconda3. To run it as a batch job, I commented out the gui related lines. It started to run for a few hrs, then stopped in the Validation step, the error message is as below. </p>
  
  <pre><code>...
  ^M100%|█████████▉| 452/453 [1:07:07&lt;00:08,  8.75s/it, 
  loss=1.23]^[[A^[[A^[[A
  
  ^MValidation:   0%|          | 0/40 [00:00&lt;?, ?it/s]^[[A^[[A^[[ATraceback 
  (most recent call last):
    File "./resnet34_pretrained_PNG_nogui_2.py", line 279, in &lt;module&gt;
      learner.fit(lr,1,callbacks=[f1_callback])
    File "/project/6000192/jemmyhu/resnet_png/fastai/learner.py", line 302, 
  in fit
      return self.fit_gen(self.model, self.data, layer_opt, n_cycle, 
  **kwargs)
    File "/project/6000192/jemmyhu/resnet_png/fastai/learner.py", line 249, 
  in fit_gen
      swa_eval_freq=swa_eval_freq, **kwargs)
    File "/project/6000192/jemmyhu/resnet_png/fastai/model.py", line 162, in 
  fit
      vals = validate(model_stepper, cur_data.val_dl, metrics, epoch, 
  seq_first=seq_first, validate_skip = validate_skip)
    File "/project/6000192/jemmyhu/resnet_png/fastai/model.py", line 241, in 
  validate
      res.append([to_np(f(datafy(preds), datafy(y))) for f in metrics])
    File "/project/6000192/jemmyhu/resnet_png/fastai/model.py", line 241, in 
  &lt;listcomp&gt;
      res.append([to_np(f(datafy(preds), datafy(y))) for f in metrics])
    File "./resnet34_pretrained_PNG_nogui_2.py", line 237, in __call__
      self.TP += (preds*targs).float().sum(dim=0)
  TypeError: add(): argument 'other' (position 1) must be Tensor, not 
  numpy.ndarray
  </code></pre>
  
  <p>The link for the original code is
  <a href="https://www.kaggle.com/iafoss/pretrained-resnet34-with-rgby-0-460-public-lb" rel="nofollow noreferrer">https://www.kaggle.com/iafoss/pretrained-resnet34-with-rgby-0-460-public-lb</a></p>
  
  <p>lines 279 and 237 in my copy are shown below:</p>
  
  <pre><code>226 class F1:
  227     __name__ = 'F1 macro'
  228     def __init__(self,n=28):
  229         self.n = n
  230         self.TP = np.zeros(self.n)
  231         self.FP = np.zeros(self.n)
  232         self.FN = np.zeros(self.n)
  233
  234     def __call__(self,preds,targs,th=0.0):
  235         preds = (preds &gt; th).int()
  236         targs = targs.int()
  237         self.TP += (preds*targs).float().sum(dim=0)
  238         self.FP += (preds &gt; targs).float().sum(dim=0)
  239         self.FN += (preds &lt; targs).float().sum(dim=0)
  240         score = (2.0*self.TP/(2.0*self.TP + self.FP + self.FN + 1e-6)).mean()
  241         return score
  
  276 lr = 0.5e-2
  277 with warnings.catch_warnings():
  278     warnings.simplefilter("ignore")
  279     learner.fit(lr,1,callbacks=[f1_callback])
  </code></pre>
  
  <p>Could anyone have a clue for the issue? </p>
  
  <p>Many thanks,
  Jemmy</p>