|
FNN 1.0.0
Toolbox to use NNs in Fortran.
|
Interface module between keras and FNN. More...
Classes | |
| class | UnsupportedLayerException |
| Exception class for unsupported layers. More... | |
| class | UnsupportedModelException |
| Exception class for unsupported models. More... | |
Functions | |
| def | keras_to_txt (filename_out, model, **kwargs) |
| Transforms a keras model into a txt model file which can be read by FNN. More... | |
| def | keras_file_to_txt (filename_out, filename_in, **kwargs) |
| Transforms a keras model file into a txt model file which can be read by FNN. More... | |
Variables | |
| string | STR_FORMAT = '{}'.format |
| Format function for strings. More... | |
| string | INT_FORMAT = '{:>7d}'.format |
| Format function for integers. More... | |
| string | FLOAT_FORMAT = '{:0.7e}'.format |
| Format function for real numbers. More... | |
Interface module between keras and FNN.
This package provides the keras_file_to_txt and keras_to_txt functions to convert a keras model into a txt file which can be read by FNN.
Use the keras_file_to_txt function as follows to convert a .h5 file into a .txt file:
>>> keras_file_to_txt('model_out.txt', 'model_in.h5')
Use the keras_to_txt function as follows to convert a keras model into a .txt file:
>>> keras_to_txt('model_out.txt', keras_model)
Use the following command to convert a .h5 file into a .txt file:
>>> python keras_to_fnn.py model_out.txt model_in.h5
| def keras_to_fnn.keras_file_to_txt | ( | filename_out, | |
| filename_in, | |||
| ** | kwargs | ||
| ) |
Transforms a keras model file into a txt model file which can be read by FNN.
This function is actually a wrapper around keras_to_txt. It accepts the same kwargs, with the addition of custom_objects.
Note
This function uses tf.keras.models.load_model to read filename_in.
Accepted kwargs
custom_objects : list of strkeras_to_txt. | [in] | filename_out | The name of the txt file to write. |
| [in] | filename_in | The keras model file. |
| [in] | kwargs | Key-word arguments. |
add_norm_in : boolnorm_alpha_in : np.ndarrayalpha (1d array) for the input normalisation layer, if any.norm_beta_in : np.ndarraybeta (1d array) for the input normalisation layer, if any.add_norm_out : boolnorm_alpha_out : np.ndarrayalpha (1d array) for the output normalisation layer, if any. | def keras_to_fnn.keras_to_txt | ( | filename_out, | |
| model, | |||
| ** | kwargs | ||
| ) |
Transforms a keras model into a txt model file which can be read by FNN.
Accepted kwargs
add_norm_in : boolnorm_alpha_in : np.ndarrayalpha (1d array) for the input normalisation layer, if any.norm_beta_in : np.ndarraybeta (1d array) for the input normalisation layer, if any.add_norm_out : boolnorm_alpha_out : np.ndarrayalpha (1d array) for the output normalisation layer, if any.norm_beta_out : np.ndarraybeta (1d array) for the output normalisation layer, if any.dropout_rates : None or float or list of floatignore_dropout : bool| [in] | filename_out | The name of the txt file to write. |
| [in] | model | The keras model. |
| [in] | kwargs | Key-word arguments. |
| string keras_to_fnn.FLOAT_FORMAT = '{:0.7e}'.format |
Format function for real numbers.
| string keras_to_fnn.INT_FORMAT = '{:>7d}'.format |
Format function for integers.
| string keras_to_fnn.STR_FORMAT = '{}'.format |
Format function for strings.