scikit-surgerytf

Segmentation

Liver Segmentation UNet

Module to implement a semantic (pixelwise) segmentation using UNet on 512x512.

class sksurgerytf.models.rgb_unet.RGBUNet(logs='logs/fit', data=None, working=None, omit=None, model=None, learning_rate=0.0001, epochs=50, batch_size=2, input_size=(512, 512, 3), patience=20)[source]

Class to encapsulate RGB UNet semantic (pixelwise) segmentation network.

Thanks to Zhixuhao, and ShawDa for getting me started, and `Harshall Lamba <https://towardsdatascience.com/understanding-semantic-segmentation-with-unet-6be4f42d4b47>_, for further inspiration.

predict(rgb_image)[source]

Method to test a single image. Image resized to match network, segmented and then resized back to match the input size.

Parameters:rgb_image – 3 channel RGB, [0-255], uchar.
Returns:single channel, [0=bg|255=fg].
save_model(filename)[source]

Method to save the whole trained network to disk.

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

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

Returns:output of self.model.evaluate on validation set, or None.
sksurgerytf.models.rgb_unet.run_rgb_unet_model(logs, data, working, omit, model, save, test, prediction, epochs, batch_size, learning_rate, patience)[source]

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

Parameters:
  • logs – directory for log files for tensorboard.
  • data – root directory of training data.
  • working – working directory for organising data.
  • omit – patient identifier to omit, when doing Leave-One-Out.
  • model – file of previously saved model.
  • save – file to save model to.
  • test – input image to test.
  • prediction – output image, the result of the prediction on test image.
  • epochs – number of epochs.
  • batch_size – batch size.
  • learning_rate – learning rate for optimizer.
  • patience – number of steps to tolerate non-improving accuracy

Fashion MNIST Example Classifer

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]

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