sksurgerytf.models.fashion module

Module to implement a basic classifier for the Fashion MNIST dataset. The aim of this module is to demonstrate how to create a class that can be developed, tested and re-used effectively. It is not a demonstration on how to do deep learning, or classification per se.

Inspired by TensorFlow tutorials.

class sksurgerytf.models.fashion.FashionMNIST(logs='logs/fit', model=None, learning_rate=0.001, epochs=1)[source]

Bases: object

Class to encapsulate a classifier for the Fashion MNIST dataset.

extract_failures(number_to_fetch)[source]

Returns incorrectly classified test images. :param number_to_fetch: int, the number to find.

This method is slow, its only for demo purposes.

Returns:indexes, images, predicted, labels
get_class_names()[source]

Returns a copy of the valid class names. We return copies to stop external people accidentally editing the internal copies. It’s safer in the long run, although in Python easy to work around.

Returns:list of strings
get_test_image(index)[source]

Extracts an image from the test data. Useful for unit testing, as the original data comes packaged up in a zip file.

Parameters:index – int [0-9999], unchecked
Returns:image, (28 x 28), numpy, single channel, [0-255], uchar.
save_model(filename)[source]

Method to save the whole trained network to disk.

Parameters:filename – file to save to.
test(image)[source]

Method to test a single (28 x 28) image.

Parameters:image – (28 x 28), numpy, single channel, [0-255], uchar.
Returns:(class_index, class_name)
train()[source]

Method to train the neural network. Writes each epoch to tensorboard log files.

Returns:output of self.model.evaluate on test set.
sksurgerytf.models.fashion.run_fashion_model(logs, model, save, test)[source]

Helper function to run the Fashion MNIST model from the command line entry point.

Parameters:
  • logs – directory for log files for tensorboard.
  • model – file of previously saved model.
  • save – file to save weights to
  • test – image to test