-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathfrd.py
More file actions
65 lines (49 loc) · 2.59 KB
/
frd.py
File metadata and controls
65 lines (49 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import torch
from monai.metrics.fid import get_fid_score
from monai.metrics.metric import Metric
__all__ = ["FrechetRadiomicsDistance", "get_frd_score"]
class FrechetRadiomicsDistance(Metric):
"""
Fréchet Radiomics Distance (FRD). Computes the Fréchet distance between two
distributions of radiomic feature vectors, in the same way as the Fréchet
Inception Distance (FID) but for radiomics-based features.
Unlike FID, FRD uses interpretable, clinically relevant radiomic features
(e.g. from PyRadiomics) and works for both 2D and 3D images, with optional
conditioning by anatomical masks. See Konz et al. "Fréchet Radiomic Distance
(FRD): A Versatile Metric for Comparing Medical Imaging Datasets."
https://arxiv.org/abs/2412.01496
This metric accepts two groups of pre-extracted radiomic feature vectors with
shape (number of samples, number of features). The same Fréchet distance
formula as in FID is applied to the mean and covariance of these features.
Args:
y_pred: Radiomic feature vectors for the first distribution (e.g. from
generated or reconstructed images), shape (N, F).
y: Radiomic feature vectors for the second distribution (e.g. from real
images), shape (N, F).
Returns:
Scalar tensor containing the FRD value.
"""
def __call__(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
return get_frd_score(y_pred, y)
def get_frd_score(y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
"""Computes the FRD score from two batches of radiomic feature vectors.
The implementation reuses the same Fréchet distance as FID; only the
semantics (radiomic features vs. deep features) differ.
Args:
y_pred: Feature vectors for the first distribution, shape (N, F).
y: Feature vectors for the second distribution, shape (N, F).
Returns:
Scalar tensor containing the Fréchet Radiomics Distance.
"""
return get_fid_score(y_pred, y)