def test_custom_model(self): # get config path and remove it so we can copy and paste the new one astroNN_config_path = config_path() if os.path.exists(astroNN_config_path): os.remove(astroNN_config_path) # copy and paste the new one from test suite test_config_path = os.path.join(os.path.dirname(astroNN.__path__[0]), 'tests', 'config.ini') shutil.copy(test_config_path, astroNN_config_path) # copy and paste the custom model from test suite to travis user space test_modelsource_path = os.path.join( os.path.dirname(astroNN.__path__[0]), 'tests', 'custom_model', 'custom_models.py') shutil.copy( test_modelsource_path, os.path.join('/home/travis/build/henrysky', 'custom_models.py')) head, tail = os.path.split(test_modelsource_path) sys.path.insert(0, head) CustomModel_Test = getattr(import_module(tail.strip('.py')), str('CustomModel_Test')) (x_train, y_train), (x_test, y_test) = mnist.load_data() y_train = utils.to_categorical(y_train, 10) # To convert to desirable type x_train = x_train.astype(np.float32) x_test = x_test.astype(np.float32) y_train = y_train.astype(np.float32)
def test_custom_model(self): import shutil import os import astroNN from astroNN.config import config_path test_config_path = os.path.join(os.path.dirname(astroNN.__path__[0]), 'tests', 'config.ini') astroNN_config_path = config_path() if os.path.exists(astroNN_config_path): os.remove(astroNN_config_path) shutil.copy(test_config_path, astroNN_config_path) test_modelsource_path = os.path.join( os.path.dirname(astroNN.__path__[0]), 'tests', 'custom_model', 'custom_models.py') shutil.copy( test_modelsource_path, os.path.join('/home/travis/build/henrysky', 'custom_models.py')) import sys from importlib import import_module head, tail = os.path.split(test_modelsource_path) sys.path.insert(0, head) CustomModel_Test = getattr(import_module(tail.strip('.py')), str('CustomModel_Test')) (x_train, y_train), (x_test, y_test) = mnist.load_data() y_train = np_utils.to_categorical(y_train, 10) # To convert to desirable type x_train = x_train.astype(np.float32) x_test = x_test.astype(np.float32) y_train = y_train.astype(np.float32) # create model instance custom_model = CustomModel_Test() custom_model.max_epochs = 1 custom_model.train(x_train[:1000], y_train[:1000]) prediction = custom_model.test(x_test[:1000]) custom_model.save('custom_model_testing_folder') custom_model_loaded = load_folder("custom_model_testing_folder") prediction_loaded = custom_model_loaded.test(x_test[:1000]) # CustomModel_Test is deterministic np.testing.assert_array_equal(prediction, prediction_loaded)
def test_custom_model(self): # get config path and remove it so we can copy and paste the new one astroNN_config_path = config_path() if os.path.exists(astroNN_config_path): os.remove(astroNN_config_path) # copy and paste the new one from test suite test_config_path = os.path.join(os.path.dirname(astroNN.__path__[0]), 'tests', 'config.ini') shutil.copy(test_config_path, astroNN_config_path) # copy and paste the custom model from test suite to travis user space test_modelsource_path = os.path.join(os.path.dirname(astroNN.__path__[0]), 'tests', 'custom_model', 'custom_models.py') shutil.copy(test_modelsource_path, os.path.join('/home/travis/build/henrysky', 'custom_models.py')) head, tail = os.path.split(test_modelsource_path) sys.path.insert(0, head) CustomModel_Test = getattr(import_module(tail.strip('.py')), str('CustomModel_Test'))
def test_config(self): from astroNN.config import config_path config_path(flag=0) config_path(flag=1) config_path(flag=2) from astroNN.config import switch_keras switch_keras('tensorflow') switch_keras('keras') # make sure flag=None raises error self.assertRaises(ValueError, switch_keras, flag=None) # make sure flag=numpy raises error self.assertRaises(ValueError, switch_keras, flag='numpy')
def test_config(self): from astroNN.config import config_path config_path(flag=0) config_path(flag=1) config_path(flag=2)