def test_resnet_architecture_module_is_used_for_resnet(self, m_custom): self.args.model_type = utils.RESNET_ARCHITECTURE for supported_mode_type in utils.SUPPORTED_MODEL_MODES: self.args.model_mode = supported_mode_type if self.args.model_mode not in self.get_unimplemented_modes_for_model_type( self.args.model_type): train_model.get_model(self.args, utils.INPUT_SHAPE) self.assertTrue(any([m_custom.called]))
def test_raises_valueError_when_unsupported_model_type_is_given(self): unsupported_model_type = 'xx' self.args.model_type = unsupported_model_type if unsupported_model_type in utils.SUPPORTED_MODEL_TYPES: self.fail( 'Test condition not right: Write the test again with proper unsupported_model_type string' ) with self.assertRaises(ValueError) as ve: train_model.get_model(self.args, utils.INPUT_SHAPE)
def test_valueError_not_raised_when_supported_model_type_is_given(self): try: for model_type in utils.SUPPORTED_MODEL_TYPES: self.args.model_type = model_type if self.args.model_mode not in self.get_unimplemented_modes_for_model_type( self.args.model_type): train_model.get_model(self.args, utils.INPUT_SHAPE) except ValueError: self.fail( '{} model architecture should be supported and should not raise error' .format(self.args.model_type))
def test_inceptionv3_architecture_module_is_used_for_inceptionv3( self, m_custom, m_finetune, m_baseline): self.args.model_type = utils.INCEPTIONV3_ARCHITECTURE for supported_mode_type in utils.SUPPORTED_MODEL_MODES: self.args.model_mode = supported_mode_type if self.args.model_mode not in self.get_unimplemented_modes_for_model_type( self.args.model_type): train_model.get_model(self.args, utils.INPUT_SHAPE) self.assertTrue( any([ m_custom.called, m_baseline.called, m_finetune.called ]))
def test_valueError_not_raised_when_supported_model_mode_is_given(self): try: for supported_mode_type in utils.SUPPORTED_MODEL_TYPES: self.args.model_type = supported_mode_type for model_mode in utils.SUPPORTED_MODEL_MODES: self.args.model_mode = model_mode model_type_unimplemented_exceptions = self.unimplemented_exceptions.get( self.args.model_type) if model_type_unimplemented_exceptions is not None \ and self.args.model_mode not in model_type_unimplemented_exceptions: train_model.get_model(self.args, utils.INPUT_SHAPE) except ValueError: self.fail( '{} model architecture should be supported and should not raise error' .format(self.args.model_type))
def load_trained_model(): model = get_model() model.load_weights(MODEL_CHECKPOINT_PATH) return model
from flask import Blueprint from flask_restx import Api, fields from train_model import get_model api = Api(version='1.0', title='ML API Example', validate=False) ns = api.namespace('heart', description='Heart disease') _, model_info = get_model() feature_row = api.model('featues', { feat: fields.Float(required=True) for feat in model_info['required_cols'] }) information = api.model( 'model information', { 'model_name': fields.String(required=True), 'f1-score': fields.Float(required=True), 'required_cols': fields.List(fields.String()) }) prediction = api.model('prediction', {'prediction': fields.Integer()}) api_blueprint = Blueprint('api', __name__)