<s> import os <EOL> import numpy as np <EOL> def save_weights ( layers , weights_dir , epoch ) : <EOL> for idx in range ( len ( layers ) ) : <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W . save_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W0 . save_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W1 . save_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT:b>' ) : <EOL> layers [ idx ] . b . save_weight ( <EOL> weights_dir , '<STR_LIT:b>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . b0 . save_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . b1 . save_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> def load_weights ( layers , weights_dir , epoch ) : <EOL> for idx in range ( len ( layers ) ) : <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W . load_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W0 . load_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . W1 . load_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT:b>' ) : <EOL> layers [ idx ] . b . load_weight ( <EOL> weights_dir , '<STR_LIT:b>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . b0 . load_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> if hasattr ( layers [ idx ] , '<STR_LIT>' ) : <EOL> layers [ idx ] . b1 . load_weight ( <EOL> weights_dir , '<STR_LIT>' + '<STR_LIT:_>' + str ( idx ) + '<STR_LIT:_>' + str ( epoch ) ) <EOL> def save_momentums ( vels , weights_dir , epoch ) : <EOL> for ind in range ( len ( vels ) ) : <EOL> np . save ( os . path . join ( weights_dir , '<STR_LIT>' + str ( ind ) + '<STR_LIT:_>' + str ( epoch ) ) , <EOL> vels [ ind ] . get_value ( ) ) <EOL> def load_momentums ( vels , weights_dir , epoch ) : <EOL> for ind in range ( len ( vels ) ) : <EOL> vels [ ind ] . set_value ( np . load ( os . path . join ( <EOL> weights_dir , '<STR_LIT>' + str ( ind ) + '<STR_LIT:_>' + str ( epoch ) + '<STR_LIT>' ) ) ) </s>
