subaligner.network module¶
-
class
subaligner.network.
Network
(secret: Optional[object], input_shape: Tuple, hyperparameters: subaligner.hyperparameters.Hyperparameters, model_path: Optional[str] = None, backend: str = 'tensorflow')[source]¶ Bases:
object
Network factory creates DNNs. Not thread safe since the session of keras_backend is global. Only factory methods are allowed when generating DNN objects.
-
BI_LSTM
= 'bi_lstm'¶
-
CONV_1D
= 'conv_1d'¶
-
LSTM
= 'lstm'¶
-
TYPES
= ['lstm', 'bi_lstm', 'conv_1d']¶
-
fit_and_get_history
(train_data: numpy.ndarray, labels: numpy.ndarray, model_filepath: str, weights_filepath: str, logs_dir: str, training_log: str, resume: bool) → Tuple[List[float], List[float]][source]¶ Fit the training data to the network and save the network model as a HDF file.
- Parameters
{numpy.array} -- The Numpy array of training data. (train_data) –
{numpy.array} -- The Numpy array of training labels. (labels) –
{string} -- The model file path. (model_filepath) –
{string} -- The weights file path. (weights_filepath) –
{string} -- The TensorBoard log file directory. (logs_dir) –
{string} -- The path to the log file of epoch results. (training_log) –
{bool} -- True to continue with previous training result or False to start a new one (default (resume) – {False}).
- Returns
tuple – A tuple contains validation losses and validation accuracies.
-
fit_with_generator
(train_data_raw: numpy.ndarray, labels_raw: numpy.ndarray, model_filepath: str, weights_filepath: str, logs_dir: str, training_log: str, resume: bool) → Tuple[List[float], List[float]][source]¶ Fit the training data to the network and save the network model as a HDF file.
- Parameters
{list} -- The HDF5 raw training data. (train_data_raw) –
{list} -- The HDF5 raw training labels. (labels_raw) –
{string} -- The model file path. (model_filepath) –
{string} -- The weights file path. (weights_filepath) –
{string} -- The TensorBoard log file directory. (logs_dir) –
{string} -- The path to the log file of epoch results. (training_log) –
{bool} -- True to continue with previous training result or False to start a new one (default (resume) – {False}).
- Returns
tuple – A tuple contains validation losses and validation accuracies.
-
classmethod
get_from_model
(model_path: str, hyperparameters: subaligner.hyperparameters.Hyperparameters) → subaligner.network.Network[source]¶ Load model into a network object.
- Parameters
{string} -- The path to the model file. (model_path) –
{Hyperparameters} -- A configuration for hyperparameters used for training. (hyperparameters) –
-
classmethod
get_network
(input_shape: Tuple, hyperparameters: subaligner.hyperparameters.Hyperparameters) → subaligner.network.Network[source]¶ Factory method for creating a network.
- Parameters
{tuple} -- A shape tuple (input_shape) –
{Hyperparameters} -- A configuration for hyperparameters used for training. (hyperparameters) –
- Returns
Network – A constructed network object.
-
get_predictions
(input_data: numpy.ndarray, weights_filepath: str) → numpy.ndarray[source]¶ Get a Numpy array of predictions.
- Parameters
{numpy.ndarray} -- The input data (input_data) –
a Numpy array. (as) –
{string} -- The weights file path. (weights_filepath) –
- Returns
numpy.ndarray – The Numpy array of predictions.
-
property
input_shape
¶ Get the input shape of the network.
- Returns
tuple – The input shape of the network.
-
property
layers
¶ Get the layers of the network.
- Returns
list – The statck of layers contained by the network
-
static
load_model_and_weights
(model_filepath: str, weights_filepath: str, hyperparameters: subaligner.hyperparameters.Hyperparameters) → subaligner.network.Network[source]¶ Load weights to the Network model.
- Parameters
{string} -- The model file path. (model_filepath) –
{string} -- The weights file path. (weights_filepath) –
{Hyperparameters} -- A configuration for hyperparameters used for training. (hyperparameters) –
- Returns
Network – Reconstructed network object.
-
property
n_type
¶ Get the type of the network.
- Returns
string – The type of the network.
-
classmethod
save_model_and_weights
(model_filepath: str, weights_filepath: str, combined_filepath: str) → None[source]¶ Combine model and weights and save to a file
- Parameters
{string} -- The path to the model file. (model_filepath) –
{string} -- The path to the weights file. (weights_filepath) –
-
classmethod
simple_fit
(input_shape: Tuple, train_data: numpy.ndarray, labels: numpy.ndarray, hyperparameters: subaligner.hyperparameters.Hyperparameters) → Tuple[List[float], List[float]][source]¶ Fit the training data to the network and save the network model as a HDF file.
- Parameters
{tuple} -- A shape tuple (input_shape) –
{numpy.array} -- The Numpy array of training data. (train_data) –
{numpy.array} -- The Numpy array of training labels. (labels) –
{Hyperparameters} -- A configuration for hyperparameters used for training. (hyperparameters) –
- Returns
tuple – A tuple contains validation losses and validation accuracies.
-
classmethod
simple_fit_with_generator
(input_shape: Tuple, train_data_raw: numpy.ndarray, labels_raw: numpy.ndarray, hyperparameters: subaligner.hyperparameters.Hyperparameters) → Tuple[List[float], List[float]][source]¶ Fit the training data to the network and save the network model as a HDF file.
- Parameters
{tuple} -- A shape tuple (input_shape) –
{list} -- The HDF5 raw training data. (train_data_raw) –
{list} -- The HDF5 raw training labels. (labels_raw) –
{Hyperparameters} -- A configuration for hyperparameters used for training. (hyperparameters) –
- Returns
tuple – A tuple contains validation losses and validation accuracies.
-
property
summary
¶ Print out the summary of the network.
-