This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import os | |
os.environ["TF_DETERMINISTIC_OPS"] = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SEED = 666 | |
import tensorflow as tf | |
tf.random.set_seed(SEED) | |
import numpy as np | |
np.random.seed(SEED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sweep_config = { | |
"method": "random", #grid, random | |
"metric": { | |
"name": "accuracy", | |
"goal": "maximize" | |
}, | |
"parameters": { | |
"epochs": { | |
"values": [10, 15, 20] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up model checkpoint callback | |
filepath = wandb.run.dir + "/{epoch:02d}-{val_accuracy:.2f}.ckpt" | |
checkpoint = tf.keras.callbacks.ModelCheckpoint(filepath, | |
monitor="val_accuracy", | |
verbose=1, | |
save_best_only=True, mode="max") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
'Cargo': 1, | |
'Military': 2, | |
'Carrier': 3, | |
'Cruise': 4, | |
'Tankers': 5 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── train | |
│ ├── images [8932 entries] | |
│ └── train.csv | |
└── test_ApKoW4T.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16') | |
model = tf.keras.models.Sequential( | |
tf.keras.layers.Input((100,)), | |
tf.keras.layers.Dense(10, dtype=policy), | |
tf.keras.layers.Dense(10, dtype=policy), | |
# Softmax should be done in float32 for numeric stability. | |
tf.keras.layers.Activation('Softmax', dtype='float32') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras import backend as K | |
K.clear_session() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16') | |
model = tf.keras.models.Sequential( | |
tf.keras.layers.Input((100,)), | |
tf.keras.layers.Dense(10, dtype=policy), | |
# Softmax should be done in float32 for numeric stability. | |
tf.keras.layers.Activation('Softmax', dtype='float32') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_model(img_size=(224,224), num_class=5, train_base=True): | |
# Accept float16 image inputs | |
input_layer = Input(shape=(img_size[0],img_size[1],3), dtype=tf.float16) | |
base = ResNet50(input_tensor=input_layer, include_top=False, | |
weights="imagenet") | |
base.trainable = train_base | |
x = base.output | |
x = GlobalAveragePooling2D()(x) | |
# softmax only accepts float32 - need to manually cast (likely a bug) | |
preds = Dense(num_class, activation="softmax", dtype=tf.float32)(x) |