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
def discriminator_loss(real_output, fake_output): | |
loss_object = tf.keras.losses.BinaryCrossentropy(from_logits=True) | |
real_loss = loss_object(tf.ones_like(real_output), real_output) | |
fake_loss = loss_object(tf.zeros_like(fake_output), fake_output) | |
total_loss = real_loss + fake_loss | |
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
def generator_loss(preds): | |
loss_object = tf.keras.losses.BinaryCrossentropy(from_logits=True) | |
preds = tf.convert_to_tensor(preds, dtype=tf.float32) | |
loss = loss_object(tf.ones_like(preds, dtype=tf.float32), preds) | |
return loss |
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
def train_step(inp, tar): | |
# targets shifted by 1 index position | |
tar_inp = tar[:, :-1] | |
tar_real = tar[:, 1:] | |
#Get encoding, combined and decoding masks | |
enc_padding_mask, combined_mask, dec_padding_mask = create_masks(inp, tar_inp) | |
# Initialize Generator and Discriminator gradient tapes | |
with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape: |
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
################################### Keras2DML: Parallely training neural network with SystemML####################################### | |
import tensorflow as tf | |
import keras | |
from keras.models import Sequential | |
from keras.layers import Input, Dense, Conv1D, Conv2D, MaxPooling2D, Dropout,Flatten | |
from keras import backend as K | |
from keras.models import Model | |
import numpy as np | |
import matplotlib.pyplot as plt |