Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
5a7d38c
cleanup
lucidtronix Feb 29, 2024
7ca56cb
cleanup
lucidtronix Feb 29, 2024
ce21db4
cleanup
lucidtronix Feb 29, 2024
71f536e
cleanup
lucidtronix Feb 29, 2024
8c999da
cleanup
lucidtronix Mar 7, 2024
0fb6efd
cleanup
lucidtronix Mar 7, 2024
1176d13
cleanup
lucidtronix Mar 7, 2024
6d68998
cleanup
lucidtronix Mar 7, 2024
2b8d695
cleanup
lucidtronix Mar 7, 2024
4b5450b
cleanup
lucidtronix Mar 7, 2024
58ee86d
cleanup
lucidtronix Mar 7, 2024
6dca73a
cleanup
lucidtronix Mar 7, 2024
16adc4d
cleanup
lucidtronix Mar 7, 2024
7016c93
cleanup
lucidtronix Mar 7, 2024
1fb4d6c
cleanup
lucidtronix Mar 7, 2024
7c23c0b
cleanup
lucidtronix Mar 7, 2024
c3eba5b
cleanup
lucidtronix Mar 7, 2024
1de3ec4
cleanup
lucidtronix Mar 7, 2024
74df559
cleanup
lucidtronix Mar 8, 2024
a7ed592
cleanup
lucidtronix Mar 8, 2024
131142f
cleanup
lucidtronix Mar 8, 2024
2d5b32b
cleanup
lucidtronix Mar 8, 2024
6db4c74
cleanup
lucidtronix Mar 8, 2024
033d57e
cleanup
lucidtronix Mar 8, 2024
5e09a3c
cleanup
lucidtronix Mar 8, 2024
a80d48e
cleanup
lucidtronix Mar 8, 2024
db9b62e
cleanup
lucidtronix Mar 8, 2024
8a95995
cleanup
lucidtronix Mar 8, 2024
88aaa76
cleanup
lucidtronix Mar 8, 2024
c6c75ec
cleanup
lucidtronix Mar 8, 2024
ef0b6dc
cleanup
lucidtronix Mar 8, 2024
cef75c3
cleanup
lucidtronix Mar 8, 2024
57301e4
cleanup
lucidtronix Mar 8, 2024
4b37e11
cleanup
lucidtronix Mar 8, 2024
9f4a03a
cleanup
lucidtronix Mar 8, 2024
fe1e287
cleanup
lucidtronix Mar 8, 2024
21c3706
cleanup
lucidtronix Mar 8, 2024
0027dd2
cleanup
lucidtronix Mar 8, 2024
d7d9214
cleanup
lucidtronix Mar 8, 2024
184929c
cleanup
lucidtronix Mar 8, 2024
d6d85dc
cleanup
lucidtronix Mar 8, 2024
2bdb9b3
cleanup
lucidtronix Mar 8, 2024
973c964
cleanup
lucidtronix Mar 8, 2024
7c0e697
cleanup
lucidtronix Mar 8, 2024
e2ae6bd
cleanup
lucidtronix Mar 8, 2024
a28fcff
cleanup
lucidtronix Mar 8, 2024
f0b0997
cleanup
lucidtronix Mar 8, 2024
a1a7ea9
cleanup
lucidtronix Mar 9, 2024
2f8a9bc
cleanup
lucidtronix Mar 15, 2024
a0f245e
cleanup
lucidtronix Mar 15, 2024
66a6819
cleanup
lucidtronix Mar 15, 2024
a8a8a76
cleanup
lucidtronix Mar 15, 2024
b1d5fcf
cleanup
lucidtronix Mar 15, 2024
c6e9b8a
cleanup
lucidtronix Mar 15, 2024
ca40299
cleanup
lucidtronix Mar 15, 2024
73de78e
cleanup
lucidtronix Mar 15, 2024
52cbc7b
cleanup
lucidtronix Mar 15, 2024
3d7d5d5
cleanup
lucidtronix Mar 15, 2024
b5d70f5
cleanup
lucidtronix Mar 15, 2024
0c16dd6
cleanup
lucidtronix Mar 15, 2024
e771dbf
cleanup
lucidtronix Mar 15, 2024
b83910e
cleanup
lucidtronix Mar 15, 2024
4697d60
cleanup
lucidtronix Mar 15, 2024
fad9279
cleanup
lucidtronix Mar 15, 2024
30f3aa6
cleanup
lucidtronix Mar 15, 2024
ba44374
cleanup
lucidtronix Mar 15, 2024
cf3ea25
cleanup
lucidtronix Mar 15, 2024
d391043
cleanup
lucidtronix Mar 15, 2024
141467c
cleanup
lucidtronix Mar 15, 2024
915da01
cleanup
lucidtronix Mar 15, 2024
a115c3f
cleanup
lucidtronix Mar 15, 2024
5e30695
cleanup
lucidtronix Mar 15, 2024
904f7a8
cleanup
lucidtronix Mar 15, 2024
07f2174
cleanup
lucidtronix Mar 15, 2024
c39bc10
cleanup
lucidtronix Mar 15, 2024
6f87803
cleanup
lucidtronix Mar 15, 2024
eb86c51
cleanup
lucidtronix Mar 16, 2024
7f4824f
cleanup
lucidtronix Mar 18, 2024
87897ea
cleanup
lucidtronix Mar 18, 2024
6090e13
cleanup
lucidtronix Mar 19, 2024
5f7c4f9
cleanup
lucidtronix Mar 19, 2024
30ebbd7
cleanup
lucidtronix Mar 19, 2024
c60f022
cleanup
lucidtronix Mar 21, 2024
93a0d5a
cleanup
lucidtronix Mar 21, 2024
aec0d36
now string
lucidtronix Apr 1, 2024
1964e04
dates
lucidtronix Apr 5, 2024
4aa980e
dates
lucidtronix Apr 5, 2024
674dfca
dates
lucidtronix Apr 11, 2024
df250cf
dates
lucidtronix Apr 11, 2024
c29eaf2
dates
lucidtronix Apr 11, 2024
be13e6e
dates
lucidtronix Apr 11, 2024
9213ac3
dates
lucidtronix Apr 12, 2024
eae3996
dates
lucidtronix Apr 12, 2024
2cbcf4b
dates
lucidtronix Apr 15, 2024
56abdb1
dates
lucidtronix Apr 15, 2024
f52e60b
dates
lucidtronix Apr 15, 2024
54c7c13
dates
lucidtronix Apr 15, 2024
2004dc6
dates
lucidtronix Apr 15, 2024
40c1815
dates
lucidtronix Apr 15, 2024
5399ca8
dates
lucidtronix Apr 15, 2024
c9ba7e1
dates
lucidtronix Apr 15, 2024
9209e39
dates
lucidtronix Apr 15, 2024
79a793e
dates
lucidtronix Apr 15, 2024
fd7c2eb
dates
lucidtronix Apr 15, 2024
23ef620
dates
lucidtronix Apr 15, 2024
22a5a34
dates
lucidtronix Apr 15, 2024
fb7ea41
dates
lucidtronix Apr 15, 2024
fc8d7e4
dates
lucidtronix Apr 15, 2024
7e1a777
dates
lucidtronix Apr 15, 2024
1014b69
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
c929e5e
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
1c356da
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
8b08014
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
4cddc9a
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
c2abeab
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
00bc685
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
9891076
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
9cf3695
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
e031e0e
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
8a48ba3
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
b7ffc67
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
3aabb28
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
d1e19e9
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
6a156b0
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
5dcbd8c
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
fea5781
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
481dcdd
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
45ef9bd
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
f40a21f
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
a005ab7
tensorflow 2.16 and keras 3
lucidtronix Apr 16, 2024
68a4bf7
save model
lucidtronix Apr 18, 2024
b51dbd8
save model
lucidtronix Apr 18, 2024
d011dc9
save model
lucidtronix Apr 18, 2024
d4adebc
save model
lucidtronix Apr 18, 2024
4790346
save model
lucidtronix Apr 18, 2024
c2ce831
save model
lucidtronix Apr 18, 2024
c682fbf
save model
lucidtronix Apr 18, 2024
ba97700
save model
lucidtronix Apr 18, 2024
2eff4dd
save model
lucidtronix Apr 18, 2024
90136ea
save model
lucidtronix Apr 18, 2024
fa51bc8
save model
lucidtronix Apr 18, 2024
182d05c
save model
lucidtronix Apr 18, 2024
f05ace3
save model
lucidtronix Apr 18, 2024
9db6b94
save model
lucidtronix Apr 18, 2024
5e2cc17
save model
lucidtronix Apr 18, 2024
541055c
save model
lucidtronix Apr 18, 2024
2d3d1db
save model
lucidtronix Apr 18, 2024
443fddc
save model
lucidtronix Apr 18, 2024
ff08d4d
save model
lucidtronix Apr 18, 2024
f4680f7
save model
lucidtronix Apr 18, 2024
4ed9e98
save model
lucidtronix Apr 19, 2024
6b33080
save model
lucidtronix Apr 19, 2024
e8852b8
save model
lucidtronix Apr 19, 2024
729ccb6
save model
lucidtronix Apr 19, 2024
b07fb54
save model
lucidtronix Apr 19, 2024
fadc936
cosh
lucidtronix Jun 18, 2024
1109100
cosh
lucidtronix Jun 18, 2024
41f7c8f
kron
lucidtronix Jul 11, 2024
3f94704
instance0 ecg bike
lucidtronix Feb 5, 2025
0b1fff9
instance0 ecg bike
lucidtronix Feb 6, 2025
1c98975
instance0 ecg bike
lucidtronix Feb 6, 2025
dc9bad0
instance0 ecg bike
lucidtronix Feb 6, 2025
df7a0d0
instance0 ecg bike
lucidtronix Feb 7, 2025
241ac69
instance0 ecg bike
lucidtronix Feb 7, 2025
9006cdd
instance0 ecg bike
lucidtronix Feb 7, 2025
47defcd
instance0 ecg bike
lucidtronix Feb 7, 2025
b48d4ad
updated model shape output and the data type of data generated (#584)
rxrathod Apr 1, 2025
fecfccc
Updates to keras layers, tensor shape handling and data generation (#…
rxrathod Apr 4, 2025
c201db5
python xdist
lucidtronix Apr 4, 2025
4418358
python xdist
lucidtronix Apr 4, 2025
f5e02f5
python xdist
lucidtronix Apr 4, 2025
f446ccc
Rr keras update (#587)
rxrathod Apr 7, 2025
6a326da
Encoder and decoder serialization and test cases (#588)
rxrathod Apr 9, 2025
1289312
activation and tensor generator fixes (#589)
rxrathod Apr 11, 2025
3ec409d
Updated test cases for ML4HT integration (#590)
rxrathod Apr 14, 2025
3d03682
parent sort argument added and drop merge is converted to class for s…
rxrathod Apr 16, 2025
20e4a0f
mae loss
lucidtronix Apr 18, 2025
12603a5
mae loss
lucidtronix Apr 18, 2025
0e6df7c
mae loss
lucidtronix Apr 18, 2025
de37b6b
mae loss
lucidtronix Apr 18, 2025
6ebc27e
Upgrade to tf-2.19 and fixes to failing test cases (#593)
rxrathod Apr 22, 2025
0b1697d
peak utils
lucidtronix Apr 22, 2025
5b78aa5
jupyter.sh
lucidtronix Apr 22, 2025
03b78e9
jupyter.sh
lucidtronix Apr 22, 2025
69de4df
jupyter.sh
lucidtronix Apr 22, 2025
df5ea37
jupyter.sh
lucidtronix Apr 22, 2025
11b26ca
jupyter.sh
lucidtronix Apr 22, 2025
2aeac51
jupyter.sh
lucidtronix Apr 22, 2025
09c8917
jupyter.sh
lucidtronix Apr 22, 2025
279f711
Updates for segmentation model (#595)
rxrathod Apr 30, 2025
e955a7f
Merge branch 'master' into sf_fuse
lucidtronix Apr 30, 2025
48a1dcc
remove neurite
lucidtronix Apr 30, 2025
a203b60
remove tfa
lucidtronix Apr 30, 2025
c370354
remove diffusion blocks
lucidtronix Apr 30, 2025
61a4eda
remove mlflow
lucidtronix Apr 30, 2025
4743498
remove mlflow
lucidtronix Apr 30, 2025
fc91ae0
test fixes (#598)
rxrathod May 1, 2025
4ac9758
remove mlflow
lucidtronix May 1, 2025
b9afd6c
remove mlflow
lucidtronix May 1, 2025
6d4c6cb
remove mlflow
lucidtronix May 1, 2025
8c1ee82
python 3.10
lucidtronix May 1, 2025
1ca128a
python 3.12
lucidtronix May 1, 2025
958c671
python 3.12
lucidtronix May 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9"]
python-version: [3.11, 3.12]

steps:
- uses: actions/checkout@v2
Expand All @@ -35,7 +35,6 @@ jobs:
python -m pip install --upgrade pip
# Install the ml4h Python package.
pip install .
pip install -r docker/vm_boot_images/config/tensorflow-requirements.txt
- name: Test with pytest
- name: Test with pytest and pytest-xdist
run: |
pytest tests -m "not slow"
pytest tests -m "not slow" -n auto
10 changes: 9 additions & 1 deletion docker/vm_boot_images/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ WORKDIR /app
# to minimize full recompilation where possible.

# Basic setup
#RUN rm /etc/apt/sources.list.d/cuda.list
##RUN rm /etc/apt/sources.list.d/nvidia-ml.list
#RUN apt-key del 7fa2af80
#RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
#RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
RUN ./ubuntu.sh

# Point any MLflow tracking hooks at the main MLflow instance on Cloud Run
Expand All @@ -32,7 +37,10 @@ ENV MLFLOW_TRACKING_URI='https://mlflow-783282864357.us-central1.run.app'
# RUN pip3 uninstall -y fastai
# RUN ./fastai.sh

RUN apt-get install python3-tk libgl1-mesa-glx libxt-dev -y
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install python3 python3-pip python3-tk libgl1-mesa-glx libxt-dev -y
RUN apt-get install -y wget unzip curl python3-pydot graphviz git ffmpeg

# Requirements for the tensorflow project
RUN pip3 install --upgrade pip
Expand Down
8 changes: 4 additions & 4 deletions docker/vm_boot_images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ CPU_ONLY="false"
PUSH_TO_GCR="false"
PUSH_TO_LATEST="false"

BASE_IMAGE_GPU="tensorflow/tensorflow:2.9.1-gpu"
BASE_IMAGE_CPU="tensorflow/tensorflow:2.9.1"
BASE_IMAGE_GPU="tensorflow/tensorflow:2.19.0-gpu"
BASE_IMAGE_CPU="tensorflow/tensorflow:2.19.0"

LATEST_TAG_GPU="tf2.9-latest-gpu"
LATEST_TAG_CPU="tf2.9-latest-cpu"
LATEST_TAG_GPU="tf2.19-latest-gpu"
LATEST_TAG_CPU="tf2.19-latest-cpu"

SCRIPT_NAME=$( echo $0 | sed 's#.*/##g' )

Expand Down
13 changes: 5 additions & 8 deletions docker/vm_boot_images/config/tensorflow-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
pydot
nibabel==4.0.2
pydicom==1.2.2
hyperopt==0.1.2
seaborn
scikit-image
peakutils
biosppy
vtk==9.2.6
imageio==2.6.1
imageio
ipywidgets>=7.5.1
bokeh
pillow
notebook
pytest
pytest-xdist
pysam
tensorflow==2.9.1
tensorflow-addons==0.17.1
tensorflow==2.19.0
tensorflow_hub
tensorflow_probability==0.17.0
tensorflow_probability
tensorflow-text
tf-models-official
keras-tuner
Expand All @@ -35,7 +33,7 @@ plotnine
vega
ipycanvas>=0.7.0
ipyannotations>=0.2.1
torch==1.12.1
torch==2.2.2
opencv-python
blosc
boto3
Expand All @@ -47,4 +45,3 @@ voxelmorph
pystrum
av
lmdb
mlflow
10 changes: 9 additions & 1 deletion docker/vm_boot_images/config/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

# Other necessities
apt-get update

echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
apt-get install -y wget unzip curl python3-pydot python3-pydot-ng graphviz ttf-mscorefonts-installer git pip ffmpeg hdf5-tools

apt-get install -y wget unzip curl python3-pydot python3-pydot-ng graphviz ttf-mscorefonts-installer git pip ffmpeg

wget https://developer.download.nvidia.com/compute/cudnn/9.8.0/local_installers/cudnn-local-repo-ubuntu2204-9.8.0_1.0-1_amd64.deb
dpkg -i cudnn-local-repo-ubuntu2204-9.8.0_1.0-1_amd64.deb
cp /var/cudnn-local-repo-ubuntu2204-9.8.0/cudnn-local-8138232B-keyring.gpg /usr/share/keyrings/
apt-get update
apt-get -y install cudnn
13 changes: 11 additions & 2 deletions ml4h/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from ml4h.TensorMap import TensorMap, TimeSeriesOrder
from ml4h.defines import IMPUTATION_RANDOM, IMPUTATION_MEAN
from ml4h.tensormap.mgb.dynamic import make_mgb_dynamic_tensor_maps
from ml4h.tensormap.tensor_map_maker import generate_categorical_tensor_map_from_file, \
generate_latent_tensor_map_from_file

from ml4h.models.legacy_models import parent_sort, check_no_bottleneck
from ml4h.tensormap.tensor_map_maker import make_test_tensor_maps, generate_random_pixel_as_text_tensor_maps
from ml4h.models.legacy_models import NORMALIZATION_CLASSES, CONV_REGULARIZATION_CLASSES, DENSE_REGULARIZATION_CLASSES
Expand Down Expand Up @@ -292,7 +295,7 @@ def parse_args():
help='Maximum number of models for the hyper-parameter optimizer to evaluate before returning.',
)
parser.add_argument('--balance_csvs', default=[], nargs='*', help='Balances batches with representation from sample IDs in this list of CSVs')
parser.add_argument('--optimizer', default='radam', type=str, help='Optimizer for model training')
parser.add_argument('--optimizer', default='adam', type=str, help='Optimizer for model training')
parser.add_argument('--learning_rate_schedule', default=None, type=str, choices=['triangular', 'triangular2', 'cosine_decay'], help='Adjusts learning rate during training.')
parser.add_argument('--anneal_rate', default=0., type=float, help='Annealing rate in epochs of loss terms during training')
parser.add_argument('--anneal_shift', default=0., type=float, help='Annealing offset in epochs of loss terms during training')
Expand Down Expand Up @@ -430,6 +433,10 @@ def parse_args():
# TensorMap prefix for convenience
parser.add_argument('--tensormap_prefix', default="ml4h.tensormap", type=str, help="Module prefix path for TensorMaps. Defaults to \"ml4h.tensormap\"")

#Parent Sort enable or disable
parser.add_argument('--parent_sort', default=True, type=lambda x: x.lower() == 'true', help='disable or enable parent_sort on output tmaps')
#Dictionary outputs
parser.add_argument('--named_outputs', default=False, type=lambda x: x.lower() == 'true', help='pass output tmaps as dictionaries if true else pass as list')
args = parser.parse_args()
_process_args(args)
return args
Expand Down Expand Up @@ -538,7 +545,7 @@ def _process_args(args):

if args.latent_input_file is not None:
args.tensor_maps_in.append(
generate_latent_tensor_map_from_file(args.latent_input_file, args.input_tensors.pop(0)),
generate_latent_tensor_map_from_file(args.latent_input_file, args.input_tensors.pop(0))
)
args.tensor_maps_in.extend([tensormap_lookup(it, args.tensormap_prefix) for it in args.input_tensors])

Expand All @@ -564,11 +571,13 @@ def _process_args(args):
args.output_tensors.pop(0),
),
)

if len(args.latent_output_files) > 0:
for lof in args.latent_output_files:
args.tensor_maps_out.append(
generate_latent_tensor_map_from_file(lof, args.output_tensors.pop(0)),
)

args.tensor_maps_out.extend([tensormap_lookup(ot, args.tensormap_prefix) for ot in args.output_tensors])
args.tensor_maps_out = parent_sort(args.tensor_maps_out)
args.tensor_maps_protected = [tensormap_lookup(it, args.tensormap_prefix) for it in args.protected_tensors]
Expand Down
2 changes: 1 addition & 1 deletion ml4h/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __str__(self):
IMAGE_EXT = '.png'
PDF_EXT = '.pdf'
TENSOR_EXT = '.hd5'
MODEL_EXT = '.h5'
MODEL_EXT = '.keras'
XML_EXT = '.xml'

STOP_CHAR = '!'
Expand Down
61 changes: 40 additions & 21 deletions ml4h/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

from sklearn.metrics import roc_curve, auc, average_precision_score


from tensorflow.keras.losses import binary_crossentropy, categorical_crossentropy, sparse_categorical_crossentropy
from tensorflow.keras.losses import logcosh, cosine_similarity, mean_squared_error, mean_absolute_error, mean_absolute_percentage_error
from tensorflow.keras.losses import LogCosh, CosineSimilarity, MSE, MAE, MAPE, Dice
from keras.saving import register_keras_serializable

from neurite.tf.losses import Dice

STRING_METRICS = [
'categorical_crossentropy','binary_crossentropy','mean_absolute_error','mae',
'mean_squared_error', 'mse', 'cosine_similarity', 'logcosh', 'sparse_categorical_crossentropy',
'mean_squared_error', 'mse', 'cosine_similarity', 'log_cosh', 'sparse_categorical_crossentropy',
]


Expand Down Expand Up @@ -48,6 +47,7 @@ def weighted_crossentropy(weights, name='anonymous'):
string_fxn += '\treturn loss\n'
exec(string_fxn, globals(), locals())
loss_fxn = eval(name + fxn_postfix, globals(), locals())
loss_fxn = register_keras_serializable()(loss_fxn)
return loss_fxn


Expand Down Expand Up @@ -109,39 +109,39 @@ def paired_angle_between_batches(tensors):

def ignore_zeros_l2(y_true, y_pred):
mask = K.cast(K.not_equal(y_true, 0), K.floatx())
return mean_squared_error(y_true * mask, y_pred * mask)
return MSE(y_true * mask, y_pred * mask)


def ignore_zeros_logcosh(y_true, y_pred):
mask = K.cast(K.not_equal(y_true, 0), K.floatx())
return logcosh(y_true * mask, y_pred * mask)
return LogCosh(y_true * mask, y_pred * mask)


def sentinel_logcosh_loss(sentinel: float):
def ignore_sentinel_logcosh(y_true, y_pred):
mask = K.cast(K.not_equal(y_true, sentinel), K.floatx())
return logcosh(y_true * mask, y_pred * mask)
return LogCosh(y_true * mask, y_pred * mask)
return ignore_sentinel_logcosh


def y_true_times_mse(y_true, y_pred):
return K.maximum(y_true, 1.0)*mean_squared_error(y_true, y_pred)
return K.maximum(y_true, 1.0)*MSE(y_true, y_pred)


def mse_10x(y_true, y_pred):
return 10.0*mean_squared_error(y_true, y_pred)
return 10.0*MSE(y_true, y_pred)


def y_true_squared_times_mse(y_true, y_pred):
return K.maximum(1.0+y_true, 1.0)*K.maximum(1.0+y_true, 1.0)*mean_squared_error(y_true, y_pred)
return K.maximum(1.0+y_true, 1.0)*K.maximum(1.0+y_true, 1.0)*MSE(y_true, y_pred)


def y_true_cubed_times_mse(y_true, y_pred):
return K.maximum(y_true, 1.0)*K.maximum(y_true, 1.0)*K.maximum(y_true, 1.0)*mean_squared_error(y_true, y_pred)
return K.maximum(y_true, 1.0)*K.maximum(y_true, 1.0)*K.maximum(y_true, 1.0)*MSE(y_true, y_pred)


def y_true_squared_times_logcosh(y_true, y_pred):
return K.maximum(1.0+y_true, 1.0)*K.maximum(1.0+y_true, 1.0)*logcosh(y_true, y_pred)
return K.maximum(1.0+y_true, 1.0)*K.maximum(1.0+y_true, 1.0)*LogCosh(y_true, y_pred)


def two_batch_euclidean(tensors):
Expand Down Expand Up @@ -265,6 +265,7 @@ def loss(y_true, y_pred):
return loss

def dice(y_true, y_pred):
return Dice()(y_true, y_pred)
return Dice(laplace_smoothing=1e-05).mean_loss(y_true, y_pred)

def per_class_dice(labels):
Expand All @@ -273,12 +274,13 @@ def per_class_dice(labels):
label_idx = labels[label_key]
fxn_name = label_key.replace('-', '_').replace(' ', '_')
string_fxn = 'def ' + fxn_name + '_dice(y_true, y_pred):\n'
string_fxn += '\tdice = Dice(laplace_smoothing=1e-05).dice(y_true, y_pred)\n'
string_fxn += '\tdice = K.mean(dice, axis=0)['+str(label_idx)+']\n'
string_fxn += '\tdice = tf.keras.losses.Dice()(y_true, y_pred)\n'
#string_fxn += '\tdice = K.mean(dice, axis=0)['+str(label_idx)+']\n'
string_fxn += '\treturn dice'

exec(string_fxn)
dice_fxn = eval(fxn_name + '_dice')
dice_fxn = register_keras_serializable()(dice_fxn)
dice_fxns.append(dice_fxn)

return dice_fxns
Expand All @@ -299,6 +301,7 @@ def per_class_recall(labels):

exec(string_fxn)
recall_fxn = eval(fxn_name + '_recall')
recall_fxn = register_keras_serializable()(recall_fxn)
recall_fxns.append(recall_fxn)

return recall_fxns
Expand All @@ -317,6 +320,7 @@ def per_class_precision(labels):

exec(string_fxn)
precision_fxn = eval(fxn_name + '_precision')
precision_fxn = register_keras_serializable()(precision_fxn)
precision_fxns.append(precision_fxn)

return precision_fxns
Expand All @@ -335,6 +339,7 @@ def per_class_recall_3d(labels):

exec(string_fxn)
recall_fxn = eval(fxn_prefix + '_recall')
recall_fxn = register_keras_serializable()(recall_fxn)
recall_fxns.append(recall_fxn)

return recall_fxns
Expand All @@ -353,6 +358,7 @@ def per_class_precision_3d(labels):

exec(string_fxn)
precision_fxn = eval(fxn_prefix + '_precision')
precision_fxn = register_keras_serializable()(precision_fxn)
precision_fxns.append(precision_fxn)

return precision_fxns
Expand All @@ -371,6 +377,7 @@ def per_class_recall_4d(labels):

exec(string_fxn)
recall_fxn = eval(fxn_prefix + '_recall')
recall_fxn = register_keras_serializable()(recall_fxn)
recall_fxns.append(recall_fxn)

return recall_fxns
Expand All @@ -389,6 +396,8 @@ def per_class_precision_4d(labels):

exec(string_fxn)
precision_fxn = eval(fxn_prefix + '_precision')
precision_fxn = register_keras_serializable()(precision_fxn)

precision_fxns.append(precision_fxn)

return precision_fxns
Expand All @@ -407,6 +416,7 @@ def per_class_recall_5d(labels):

exec(string_fxn)
recall_fxn = eval(fxn_prefix + '_recall')
recall_fxn = register_keras_serializable()(recall_fxn)
recall_fxns.append(recall_fxn)

return recall_fxns
Expand All @@ -425,6 +435,7 @@ def per_class_precision_5d(labels):

exec(string_fxn)
precision_fxn = eval(fxn_prefix + '_precision')
precision_fxn = register_keras_serializable()(precision_fxn)
precision_fxns.append(precision_fxn)

return precision_fxns
Expand All @@ -449,15 +460,15 @@ def get_metric_dict(output_tensor_maps):
elif tm.loss == 'binary_crossentropy':
losses.append(binary_crossentropy)
elif tm.loss == 'mean_absolute_error' or tm.loss == 'mae':
losses.append(mean_absolute_error)
losses.append(MSE)
elif tm.loss == 'mean_squared_error' or tm.loss == 'mse':
losses.append(mean_squared_error)
losses.append(MSE)
elif tm.loss == 'cosine_similarity':
losses.append(cosine_similarity)
elif tm.loss == 'logcosh':
losses.append(logcosh)
losses.append(CosineSimilarity)
elif tm.loss == 'log_cosh':
losses.append(LogCosh)
elif tm.loss == 'mape':
losses.append(mean_absolute_percentage_error)
losses.append(MAPE)
elif hasattr(tm.loss, '__name__'):
metrics[tm.loss.__name__] = tm.loss
losses.append(tm.loss)
Expand Down Expand Up @@ -857,4 +868,12 @@ def result(self):
def reset_state(self):
# Reset the metric state variables
self.total_ssim.assign(0.0)
self.count.assign(0.0)
self.count.assign(0.0)


def _register_all(module_globals):
for name, obj in module_globals.items():
if callable(obj) and not name.startswith("_"):
module_globals[name] = register_keras_serializable()(obj)

_register_all(globals())
Loading