def test_tf_dataset_load_prepare_fashion_mnist_incompatible_shape(): """ Load Fashion MNIST dataset (quick), attempt to prepare for input with less dimensions """ test_data = DataSet() load_test_data('fashion_mnist', test_data, 128) with pytest.raises(ModelError): test_data.x_format = keras_prepare_input(np.float, np.array([None, 32]), test_data.x)
def test_keras_list_models(): model_sequence = KerasModelSequence(DataSet()) model_paths = model_sequence.list_models(['./dnnviewer-data/models']) assert len(model_paths) > 0
def test_tf_dataset_load_prepare_fashion_mnist(): """ Load Fashion MNIST dataset (quick), prepare for model with 32x32 input """ test_data = DataSet() load_test_data('fashion_mnist', test_data, 128) assert test_data.mode is DataSet.MODE_FILESET assert np.array_equal(test_data.x.shape, [128, 28, 28, 1]) assert test_data.x.dtype is np.dtype('|u1'), "uint8" assert np.array_equal(test_data.y.shape, [128]) assert test_data.y.dtype is np.dtype('<i8'), "int64" test_data.x_format = keras_prepare_input(np.float, np.array([None, 32, 32, 1]), test_data.x) assert np.array_equal(test_data.x_format.shape, [128, 32, 32, 1]) assert test_data.x_format.dtype is np.dtype('<f8'), "float32"
def test_tf_dataset_load_mnist(): """ Load MNIST dataset (quick)""" test_data = DataSet() load_test_data('mnist', test_data, 128) assert test_data.mode is DataSet.MODE_FILESET assert np.array_equal(test_data.x.shape, [128, 28, 28, 1]) assert np.array_equal(test_data.y.shape, [128])
def test_keras_list_model_sequences(): model_sequence = KerasModelSequence(DataSet()) model_paths = model_sequence.list_models( ['./dnnviewer-data/models/FashionMNIST_checkpoints'], '{model}_{epoch}') assert len(model_paths) == 3 assert model_paths[ 0] == 'dnnviewer-data/models/FashionMNIST_checkpoints/model1_{epoch}' assert model_paths[ 1] == 'dnnviewer-data/models/FashionMNIST_checkpoints/model2_{epoch}' assert model_paths[ 2] == 'dnnviewer-data/models/FashionMNIST_checkpoints/model3_{epoch}'
def test_tf_keras_prepare_labels_unneeded(): """ Prepare labels in case unneeded """ test_data = DataSet() load_test_data('fashion_mnist', test_data, 128) assert np.array_equal(test_data.y.shape, [128]) assert test_data.y.dtype is np.dtype('<i8'), "int32" model = keras.models.Sequential([keras.layers.Dense(10)]) model.compile(loss=keras.losses.BinaryCrossentropy()) prepared_labels = keras_prepare_labels(model, test_data.y) assert np.array_equal(prepared_labels.shape, [128]), "unchanged from input labels"
def test_tf_keras_prepare_labels(): """ Prepare labels in case of categorical crossentropy loss """ test_data = DataSet() load_test_data('fashion_mnist', test_data, 128) assert np.array_equal(test_data.y.shape, [128]) assert test_data.y.dtype is np.dtype('<i8'), "int32" model = keras.models.Sequential([keras.layers.Dense(10)]) model.compile(loss=keras.losses.CategoricalCrossentropy(from_logits=False)) prepared_labels = keras_prepare_labels(model, test_data.y) assert np.array_equal(prepared_labels.shape, [128, 10]) assert prepared_labels.dtype is np.dtype('<f4'), "float32"
async def run_app(args): """ Run the app """ logger = logging.getLogger('dnnviewer') # create console handler console_handler = logging.StreamHandler() formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') console_handler.setFormatter(formatter) logger.addHandler(console_handler) numeric_level = getattr(logging, args.log_level.upper(), None) if isinstance(numeric_level, int): logger.setLevel(numeric_level) console_handler.setLevel(numeric_level) # Create App, set stylesheets app = dash.Dash( __name__, assets_folder="assets", external_stylesheets=[dbc.themes.BOOTSTRAP, font_awesome.CDN_CSS_URL]) app.title = 'DNN Viewer' # Parameters for model selection model_selection = {} # Test data test_data = DataSet() model_selection['test_dataset'] = args.test_dataset model_selection['test_mode'] = DataSet.MODE_FILESET # Default in any case # Model sequence : currently only supporting from Keras model_sequence = KerasModelSequence(test_data) # Initialize the model sequence model_selection['model'] = args.model_keras model_selection['sequence'] = args.sequence_keras preselection = True and model_selection['model'] or model_selection[ 'sequence'] # Model selection if args.model_directories: model_selection['directories'] = args.model_directories.split(',') else: model_selection['directories'] = [] model_selection['pattern'] = args.sequence_pattern # Top level pages grapher = Grapher() router = Router() router.add_route( '/', MainModelSelection(app, model_selection, model_sequence, test_data, grapher)) router.add_route( '/network-view', MainNetworkView(app, model_sequence, test_data, grapher, not preselection)) def main_layout(): return router.layout() # Top level layout : manage URL + current page content app.layout = main_layout # Install the callbacks [p.callbacks() for p in router.pages.values()] router.callbacks(app) # Run the server, will call the layout app.run_server(debug=args.debug) app.serve_routes()