This file contains hidden or 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
function image_pad_or_crop(image, output_height, output_width) { | |
// Pads or crops an image so that the height and width dimensions match output_height and output_width. | |
// This function is compatible with tf.image.resize_with_crop_or_pad(image, target_height, target_width) | |
// Validate inputs | |
const image_size = image.height * image.width * image.depth; | |
if (image.data.length != image_size) { | |
console.log("Error: image dimensions do not match rgba buffer size!"); | |
return null; | |
} |
This file contains hidden or 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 | |
# Reset states (to be sure) | |
tf.keras.backend.clear_session() | |
# Method 1 | |
x = tf.keras.Input(shape=(224, 224, 3), dtype=tf.uint8) | |
c = tf.keras.layers.Flatten()(x) | |
y = tf.keras.layers.Dense(units=2, activation="softmax")(c) | |
model1 = tf.keras.Model(inputs=x, outputs=y) |
This file contains hidden or 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
class CosineDecayWithWarmup(tf.keras.optimizers.schedules.LearningRateSchedule): | |
def __init__( | |
self, | |
warmup_steps, | |
total_steps, | |
base_lr=0.001, | |
): | |
super(CosineDecayWithWarmup, self).__init__() | |
self.warmup_steps = warmup_steps |
OlderNewer