text: import pathlib
  import IPython
  import numpy as np
  import pygmalion as ml
  import pygmalion.neural_networks as nn
  import matplotlib.pyplot as plt
  plt.style.use("bmh")
  data_path = pathlib.Path(__file__).parent / "data" / "fashion-MNIST"
  
  # Download the data
  ml.datasets.fashion_mnist(data_path.parent)
  
  # Load data
  with open(data_path / "classes.txt", "r") as file:
      data = file.read()
  classes = data.split(",")
  x_train = np.load(data_path / "train_images.npy")
  y_train = np.array(classes)[np.load(data_path / "train_labels.npy")]
  x_test = np.load(data_path / "test_images.npy")
  y_test = np.array(classes)[np.load(data_path / "test_labels.npy")]
  in_features = 1
  
  # Create and train the model
  conv = [[{"window": (3, 3), "features": 16, "dropout": 0.2, "padded": False},
           {"window": (3, 3), "features": 16, "dropout": 0.2}],
          [{"window": (3, 3), "features": 32, "dropout": 0.2, "padded": False},
           {"window": (3, 3), "features": 32, "dropout": 0.2}],
          [{"window": (3, 3), "features": 64, "dropout": 0.2, "padded": False},
           {"window": (3, 3), "features": 32, "dropout": 0.2}]]
  pooling = [(2, 2), (2, 2)]
  dense = [{"features": 16}]
  model = nn.ImageClassifier(in_features, classes,
                             convolutions=conv,
                             pooling=pooling,
                             dense=dense,
                             activation="leaky_relu",
                             GPU=0)
  # print(model.module.shapes)
  train_data, val_data = ml.split(x_train, y_train, frac=0.2)
  model.train(train_data, val_data, n_epochs=300, batch_size=1000,
              n_batches=1, learning_rate=1.0E-3)
  
  # Plot results
  model.plot_history()
  f, ax = plt.subplots()
  y_pred = sum([model(x_test[i:i+100]) for i in range(0, len(x_test), 100)], [])
  ml.plot_matrix(ml.confusion_matrix(y_pred, y_test), ax=ax, color_bar=True)
  acc = ml.accuracy(y_pred, y_test)
  ax.set_title(f"Accuracy = {acc:.3g}")
  f.tight_layout()
  
  # Plot metrics
  lx, ly = 5, 5
  x = x_test[np.random.permutation(len(x_test))[:lx*ly]]
  y = model(x)
  f, axes = plt.subplots(figsize=[8, 8], ncols=lx, nrows=ly)
  for n in range(lx*ly):
      i = n // lx
      j = n % lx
      ax = axes[i, j]
      ax.imshow(x[n], cmap="Greys")
      ax.set_title(y[n])
      ax.grid(False)
      ax.set_xticks([])
      ax.set_yticks([])
  f.tight_layout()
  
  plt.show()
  IPython.embed()
  