Tensorflow Utils¶
This is tensorflow utils
from preeminence_utils import tf_utils
model = tf_utils.Model()
Helper functions for using while making a neural network using tensorflow
-
class
tf_utils.
Model
¶ -
get_latest_checkpoint
(checkpoint_path='./model_weights/')¶ Get the name of the latest checkpoint in the checkpoints directory in order to load the latest weights to continue training for that point.
Parameters: checkpoint_path – Custom directory where checkpoints are saved Returns:
-
graph_info
()¶ Get ops in the graph
Returns: Graph ops
-
init
()¶ Initialise a new model and return its graph. This function will spawn a new graph and return it. You’ll have to set it to default graph in order to add ops to it. Sample: model = tf_utils.Model() model_graph = model.init().as_default()
Returns: Returns a new graph.
-
next_batch
(data, batch_start, batch_size)¶ Get next batch from the training data This should be a generator function :/
Parameters: - data – Training data
- batch_start – batch start index
- batch_size – size of the batch
Returns:
-
restore_weights
(checkpoint_path='./model_weights/')¶ Restore weights from the checkpoint path to the latest checkpoint to resume training from that point.
Parameters: checkpoint_path – Custom directory where checkpoints are saved Returns:
-
save_weights
(checkpoint_path=None, checkpoint_number=None)¶ Save the current weights of the model to disk at the checkpoint path. :param checkpoint_path: Custom directory where checkpoints are saved :param checkpoint_number: Custom number to append at the end of checkpoint :return:
-
session
()¶ Create and return a new session for training.
Returns: New session object
-
train
(ops, x, y, x_data, y_data, num_epochs=1, batch_size=1)¶ Training function. Executes the graph on a given dataset.
Parameters: - ops – Graph ops to be calculated and returned. Must be [optimiser_op,loss_op]
- x – placeholder tensor for x
- y – placeholder tensor for y
- x_data – Training data to be fed into x
- y_data – Training data to be fed into y
- num_epochs – Number of epochs to be executed
- batch_size – Size of a batch to be fed at a time
Returns: Nothing
-
visualise
(logdir='./logs')¶ Save graph summary in the logidr to be visualised by tensorboard. Summaries for individual ops to be added.
Parameters: logdir – Destination for storing graph logs. ./logs by default Returns: Nothing
-