Update processing_cxrmate2.py
Browse files- processing_cxrmate2.py +11 -2
processing_cxrmate2.py
CHANGED
|
@@ -19,10 +19,8 @@ from transformers.tokenization_utils_base import PreTokenizedInput, TextInput
|
|
| 19 |
|
| 20 |
try:
|
| 21 |
from .dataset import CXRMate2Dataset
|
| 22 |
-
from .utils import compute_time_delta
|
| 23 |
except ImportError:
|
| 24 |
from dataset import CXRMate2Dataset
|
| 25 |
-
from utils import compute_time_delta
|
| 26 |
|
| 27 |
# Ordered by oblique, lateral, AP, and then PA views so that PA views are closest in position to the generated tokens (and oblique is furtherest).
|
| 28 |
VIEW_ORDER = [
|
|
@@ -52,6 +50,17 @@ VIEW_ORDER = [
|
|
| 52 |
]
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
class CXRMate2Processor(transformers.ProcessorMixin):
|
| 56 |
|
| 57 |
attributes = ['image_processor', 'tokenizer']
|
|
|
|
| 19 |
|
| 20 |
try:
|
| 21 |
from .dataset import CXRMate2Dataset
|
|
|
|
| 22 |
except ImportError:
|
| 23 |
from dataset import CXRMate2Dataset
|
|
|
|
| 24 |
|
| 25 |
# Ordered by oblique, lateral, AP, and then PA views so that PA views are closest in position to the generated tokens (and oblique is furtherest).
|
| 26 |
VIEW_ORDER = [
|
|
|
|
| 50 |
]
|
| 51 |
|
| 52 |
|
| 53 |
+
def compute_time_delta(event_time, reference_time, to_tensor=True):
|
| 54 |
+
time_delta = reference_time - event_time
|
| 55 |
+
time_delta = time_delta.total_seconds()
|
| 56 |
+
assert isinstance(time_delta, float), f'time_delta should be float, not {type(time_delta)}.'
|
| 57 |
+
if time_delta < 0:
|
| 58 |
+
raise ValueError(f'time_delta should be greater than or equal to zero, not {time_delta}.')
|
| 59 |
+
if to_tensor:
|
| 60 |
+
time_delta = torch.tensor(time_delta)
|
| 61 |
+
return time_delta
|
| 62 |
+
|
| 63 |
+
|
| 64 |
class CXRMate2Processor(transformers.ProcessorMixin):
|
| 65 |
|
| 66 |
attributes = ['image_processor', 'tokenizer']
|