NAS Interface#
(hivenas.core.nas.nas_interface)
The NAS Interface encapsulating the Evaluation Strategy and Search Space.
- class NASInterface(space_config=None, eval_config=None)[source]#
Bases:
ObjectiveInterfaceAn interface that combines the Search Space & Evaluation Strategy for the NAS Search Algorithm (ABC)
- cls.search_space#
NASSearchSpace instance used to sample candidates and neighbors
- Type
- evaluate(candidate)[source]#
Evaluates a given candidate architecture
- Parameters
candidate (str) – string-encoded representation of the architecture to be evaluated
- Returns
a dictionary containing all relevant results to be saved, including: fitness, number of training epochs conducted (in case of ACT), hashed file name, number of trainable parameters, and the last epoch’s momentum value if applicable
- Return type
dict
- fully_train_best_model(from_arch=True)[source]#
Fully-train best-performing model (relies on paths set in
Params)- Parameters
from_arch (bool, optional) – determines whether to train model from scratch using the string representations of the architecture (
from_arch = True) or load the saved model file and continue training (from_arch = False). Note: optimizer settings are typically not saved, therefore training continuation from a model’s file can result in a worse overall accuracy (read more…).- Returns
a dictionary containing all relevant results to be saved, including: fitness, number of training epochs conducted (not including any previous trainings), hashed file name, number of trainable parameters
- Return type
dict
- Raises
FileNotFoundError – raises an error if the results file or model h5 file (when applicable) do not exist
- get_neighbor(orig_arch)[source]#
Returns a random architecture with 1 op diff to the given candidate
- Parameters
orig_arch (str) – string-encoded representation of the candidate architecture
- Returns
string-encoded representation of the neighbor architecture
- Return type
str
- property is_minimize#
Used by the optimization algorithm to determine whether this is a minimization or maximization problem
- Returns
hard-coded
False; the search algorithm is always maximizing accuracy- Return type
bool
- momentum_eval(candidate, weights_filename, m_epochs)[source]#
Trains a given network for additional
m_epochs- Parameters
candidate (str) – string-encoded representation of the candidate architecture
weights_filename (str) – the SHA1-hashed unique string ID for the given architecture
m_epochs (int) – the additional momentum epochs the candidate should be trained for
- Returns
final fitness value (accuracy) after training continuation
- Return type
dict
- sample()[source]#
Samples new random candidate architecture from the search space
- Returns
string-encoded representation of the sampled candidate architecture
- Return type
str
- train_custom_arch(arch_str)[source]#
Fully trains a given string-encoded architecture (primarily used for debugging)
- Parameters
arch_str (str) – string-encoded representation of the architecture
- Returns
a dictionary containing all relevant results to be saved, including: fitness, number of training epochs conducted (not including any previous trainings), hashed file name, number of trainable parameters
- Return type
dict