User Tools

Site Tools


auto2d_tutorial
This version (2020/08/28 07:37) was approved by twagner.The Previously approved version (2020/03/10 18:17) is available.Diff

How to use SPHIRE's Cinderella for 2D class selection

This tutorial describes how to use Cinderella to classify 2D class averages. You can either use a pretrained model (see section Classify) or train your own model (see section Training).

Download & Install

You can find the download and installation instructions here: Download and Installation

Classify

I suppose you downloaded the latest classification model.

To run the classification I suppose you want to separate good and bad classes in classes_after_isac.hdf (or any other .mrcs / .hdf file with classes) and you want to save your new .hdf (.mrcs) files into the folder output_folder. Furthermore you want to use the model model.h5 and the GPU with ID=1. Classes with a confidence bigger than 0.7 should be classified as good class.

This is the command to run:

sp_cinderella_predict.py -i path/to/classes_after_isac.hdf -w model.h5 -o output_folder/ -t 0.7 --gpu 1

You will find the files classes_after_isac_good.hdf and classes_after_isac_bad.hdf in your output_folder.

Training

If you would like to train Cinderella with your own classes, you can easily do it. First you have to separate your good and bad classes into separate files. Create two folders, one containing good classes (e.g GOOD_CLASSES/) and one contain bad classes (e.g BAD_CLASSES/). Both folders can contain multiple .hdf / .mrcs files.

Then specify the paths into a config file like this:

config.json
{
	"model": {
		"input_size": [64,64]
	},
 
	"train": {
		"batch_size": 32,
		"good_path": "GOOD_CLASSES/",
		"bad_path": "BAD_CLASSES/",
		"pretrained_weights": "",
		"saved_weights_name": "my_model.h5",
		"learning_rate": 1e-4,
		"nb_epoch": 100,
		"nb_early_stop": 15
	}
}

The fields in the section model have the following meaning:

  • input_size: This is the image size to which each class is resized to.
  • mask_radius: (Optional) Circular mask radius which is applied after resizing to the input size. If not given, it uses 0.4*input_size as default.

The fields in the section train have the following meaning:

  • batch_size: How many classes are in one mini-batch. If you have memory problems, you can try to reduce this value.
  • good_path: Path to folder with good classes.
  • bad_path: Path to folder with bad classes.
  • pretrained_weights: Path to weights that are used to initialize the network. It can be empty. As Cinderella is using the same network architecture as crYOLO, we are typically using the general network of crYOLO as pretrained weights.
  • saved_weights_name: Final model filename
  • learning_rate: Learning rate, should not be changed.
  • nb_epoch: Maximum number of epochs to train. However, it will stop earlier (see nb_early_stop).
  • nb_early_stop: If the validation loss did not improve “nb_early_stop” times in a row, the training will stop automatically.

The next step is to run the training:

sp_cinderella_train.py -c example_config.json --gpu 1

This will train a classification network on the GPU with ID=1. After the training finishes, you get a my_model.h5 file. This can then be used to predict good / bad classes.

auto2d_tutorial.txt · Last modified: 2020/08/28 07:36 by twagner