Natooz commited on
Commit
9db8383
·
unverified ·
1 Parent(s): 78003b9

fix input format conversion

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. ece.py +3 -5
README.md CHANGED
@@ -24,8 +24,8 @@ https://torchmetrics.readthedocs.io/en/stable/classification/calibration_error.h
24
 
25
  ### Inputs
26
  *List all input arguments in the format below*
27
- - **input_field** *(tensor or numpy array, float32): predictions (after softmax). They must have a shape (N,C,...) if multiclass, or (N,...) if binary.*
28
- - **references** *(tensor or numpy array, int64): reference for each prediction, with a shape (N,...).*
29
 
30
  ### Output Values
31
 
 
24
 
25
  ### Inputs
26
  *List all input arguments in the format below*
27
+ - **predictions** *(float32): predictions (after softmax). They must have a shape (N,C,...) if multiclass, or (N,...) if binary.*
28
+ - **references** *(int64): reference for each prediction, with a shape (N,...).*
29
 
30
  ### Output Values
31
 
ece.py CHANGED
@@ -16,7 +16,7 @@ from typing import Dict
16
 
17
  import evaluate
18
  import datasets
19
- from torch import from_numpy, amax
20
  from torchmetrics.functional.classification.calibration_error import (
21
  binary_calibration_error,
22
  multiclass_calibration_error,
@@ -106,10 +106,8 @@ class ECE(evaluate.Metric):
106
  be used as "num_classes".
107
  """
108
  # Convert the input
109
- if isinstance(predictions, ndarray):
110
- predictions = from_numpy(predictions)
111
- if isinstance(references, ndarray):
112
- references = from_numpy(references)
113
 
114
  max_label = amax(references, list(range(references.dim())))
115
  if max_label > 1 and "num_classes" not in kwargs:
 
16
 
17
  import evaluate
18
  import datasets
19
+ from torch import Tensor, LongTensor, amax
20
  from torchmetrics.functional.classification.calibration_error import (
21
  binary_calibration_error,
22
  multiclass_calibration_error,
 
106
  be used as "num_classes".
107
  """
108
  # Convert the input
109
+ predictions = Tensor(predictions)
110
+ references = LongTensor(references)
 
 
111
 
112
  max_label = amax(references, list(range(references.dim())))
113
  if max_label > 1 and "num_classes" not in kwargs: