There is an important custom loss function that is needed for the generator network: the self-regularization loss. We'll define this function as though it's part of our helper functions in the generator:
- Define self-regularization loss as follows:
def self_regularization_loss(self,y_true,y_pred):
return tf.multiply(0.0002,tf.reduce_sum(tf.abs(y_pred-y_true)))
- Create the summary helper function, as follows:
def summary(self):
return self.Generator.summary()
- Define the save_model_graph function as in previous sections, as follows:
def save_model_graph(self):
plot_model(self.Generator, to_file='/out/Generator_Model.png')
- Save the model h5 file if requested by the user with the following code:
def save_model(self,epoch,batch):
self.Generator.save('/out/'+self.NAME+'_Epoch_'+epoch+'_Batch_'+batch+
'model.h5')