我正在尝试在fastai表格模型上更改默认阈值0.5,但无法使其正常工作。
我正在使用最新版本的fastai + conda和python3来运行它
f1_score =FBeta(average='macro',beta = 1)
acc_02 = partial(accuracy_thresh, thresh=0.2)
f_score = partial(fbeta, thresh=0.2)
learn = tabular_learner(data, layers=[1000, 200, 15], emb_szs=emb_szs, metrics=[acc_02,f1_score],emb_drop=0.1, callback_fns=ShowGraph)```
I would expect to set the tresh to 0.2 but I'm getting the following error:
```python
RuntimeError Traceback (most recent call last)
<ipython-input-196-fd2bddb11935> in <module>()
----> 1 learn.fit_one_cycle(2, max_lr=slice(1e-01))
8 frames
/usr/local/lib/python3.6/dist-packages/fastai/metrics.py in accuracy_thresh(y_pred, y_true, thresh, sigmoid)
33 "Computes accuracy when `y_pred` and `y_true` are the same size."
34 if sigmoid: y_pred = y_pred.sigmoid()
---> 35 return ((y_pred>thresh).byte()==y_true.byte()).float().mean()
36
37 def top_k_accuracy(input:Tensor, targs:Tensor, k:int=5)->Rank0Tensor:
RuntimeError: The size of tensor a (2) must match the size of tensor b (64) at non-singleton dimension 1```