Package: celldeath
celldeathPython-based deep learning model optimized for classifying cultures undergoing cell death or not in transmitted light microscopy images.Our goal is to provide a tool for researchers with none or minimal idea of deep learning.Getting Startedcelldeath is a deep learning tool that trains with light transmitted microscopy images in order to predict cell death/apoptosis.We aimed to keep it simple, so anyone can implement it with minimal deep learning knowledge. Parameters for training are already optimized for high accuracy. However, we provide some suggestions for fine tunning your training, as each experimental model may have unique features.PrerequisitesPlease note that for training a deep learning model you need a GPU and lots of images. If you don't have a GPU available, you can try in any cloud computing provider (AWS, Google Cloud, Azure, etc).InstallingFor installation, we suggest that you create an environment, and then:pipinstallcelldeathDependenciesfastai>=1.0.60image-slicer==0.3.0matplotlib>=3.1.1torch==1.4torchvision==0.5.0Usagecelldeath has three modules (train,predictandslice), each one with options of their own (see section Modules for details). However, for a shorter version, you can follow these next steps using default parameters.LabellingFor image labelling, you can include in each of your image filenames either the string 'control' or the string 'celldeath'. These are defaults, but you can change them with the argument -labels, or even include more categories.# possible naming formatstestFile_control_RGB_1h.png
testFile_celldeath_RGB_1h.pngShort versionOpen your terminal and typecelldeathslice-indir_slicingyour/img/folder# path to your input images; output is directed by default to img_split_train, unless -train_path argument is providedBe aware that if you train several times with the same images, this previous step has to be done just once. This command will slice your images into 4 tiles, which will be used later for training.celldeathtrain-labelsyour_labels-imagenet# example for label input: -lables control celldeathYou have to provide your labels, which must be included as part of the filename in each image. Default values arecontrolandcelldeath. You can have more than 2 conditions though.Default values should lead to high accuracy in your images for prediction. (Of course, your images should be good enough...) Once training is finished, you will find a report file in ~/celldeah directory that includes all training parameters, results on the validation image set, and accuracy on the test set if performed. You will also get a confusion matrix with absolute numbers for prediction and the Loss curve for training and validation.ModulesThe next subcommands will give you some more control on preprocessing, training and prediction. Subcommands are:celldeath slice| Only need to run once, and only if you wish to slice your images.celldeath train| Core subcommand for training the neural network.celldeath predict| One or more images are given and it returns prediction based on your previous training.SLICEYour training and prediction may improve as the number of images that you provide increases. If cells were homogeneously seeded in your experiments you may find this module useful. Slice will divide your picture into n tiles (default is 4), and hence increase the number of images. As long as the slicing process does not add images without cells, you can increase your slicing up to 8 per image. For example, a typical image size is 1920x1440 pixels, and hence after slicing into 4 tiles, we trained with 480x360 pixels images.Also, it is a good practice to split your images into three sets: trainig, validation and test. Prediction on this last set is independent of training, and so recommended. To create a test set, add the -test_path option and the desired percentage of image to include (-perc_test).Examplecelldeathslice-indir_slicingpath/to/input-train_path~/img_split_train-n_tiles4-test_pathyour_path/img_split_test-perc_testSlice optionscommanddescription-h, --helpshow this help message and exit-indir_slicingFolder where images are stored.-train_pathPath where sliced images are saved.-n_tilesNumber of tiles to generate. Default is 4; allowed values are 2,4,6 and 8.-test_pathPath where images for testing will be stored. Default is img_split_test.-perc_testPercentage of images that will be used for testing. (No default here!)TRAINcelldeath allows you to train your own images without too much knowledge on deep learning. Be aware though, that you need at least a few hundred images for proper training and prediction. However, as mentioned before, with theslicemodule you can split your images into n tiles (usually 4) increasing your training performance. Also, using the argument -aug will artificially increase the information gathered from each image by flipping and rotating them. Thetrainmodule already has most options set up for an excellent training, as mentioned in the short version section.Minimal example with pretrained models (imagenet)celldeathtrain-imagenetIn this minimal example, you just need to put your images in'~/celldeath/img_split_train/'(default path if you used the slice module, see SLICE section), and make sure your filenames contain the labels'control'or'celldeath', acording to your experiments. The-imagenetoption allows you to use a neural network previously trained (withimagenet), which may result in a accurate short-running-time training. However, in our experience it did not produce better results (lower test accuracy).Extended example (defaults are shown)celldeathtrain-indir/your/path/img-labelscontrolcelldeath-modelresnet50-valid_pc0.2-l_lr1e-4-u_lr1e-3-aug-epochs50-bs16-dropout0.5-wd0.01-test_pathyour/path/to/test/img# 'control' and 'celldeath' labels are shown, but you may use your own as long as they can be found somewhere in the filenameTrain optionsShort explanations about these options are given below. Some of them may have a huge impact in your training; we suggest you to try small changes in each one of them in order to get your best trained model.commanddescriptionsuggestion-h, --helpshow this help message and exit-indirFolder where input images are stored. Default is '/img_split_train' (resulting from slice module)-labelsGive labels of each experimental condition. Labels should be written as in the filenames. Default values are 'control' and 'celldeath'.-modelModel used for training. Default is ResNet50. Models available are resnet34, resnet50, resnet101, and densenet121.Trying larger architectures will take longer to train.-valid_pctValidation percentage. Default is 0.2-l_lrLower Limit for learning rate. Default is 1e-4You may try 1e-5 or even 1e-6-u_lrUpper limit for learning rate. Default is 1e-3-augAdd image augmentation. Default FalseAlways try it.-epochsNumber of epochs. Default is 50.Longer training may be beneficial to detect porential overfitting if imagenet option is false.-bsBatch SizeDepends on the RAM of your GPU. Default is 16.-dropoutDropout to be applied. Defaults is 0.5Try 0.6-0.25-wdDefault is 0.01Try 0.1 or 0.001-imagenetDefine if training with imagnet pretrained weights. Default is False.-test_pathPath where test input images are located. Default is '/img_split_test'.Train resultsAfter training, a report file will be saved in a folder calledcelldeath(created in your home dir) with accuracy, precision and recall, as well as confusion matrix values. Also, a .csv file namedhistory+current time will be saved with each of the training loss and accuracy values per epoch.In addition, four plots will be saved in this directory:Learning curve with training and validation sets (Loss function)AccuracyValidation confusion matrixTest confusion matrixA few recommendations:be consistent in your experimental conditions.get as many images as possible all over the well.try both pretrained (-imagenet) and not pretrained. Pretrainng may be faster, but it is not necessarily better though (there are no cells in imagenet).try augmentation. We set up a few augmentation parameters (flip and rotation, minimal changes in light condition) since some other common arguments result in a lower performance.batch size (-bs) will depend on your GPU and the size of your images.Always try weight decay. We set it up to 0.01, but also try 0.1.train with many epochs, particularly if you are not using a pretrained network. It may take 40-50 epochs to achieved a fully trained model.PREDICTAfter training, you can predict the presence of cell death in a set of images by using thepredictoption. By default, the trained model is saved inside 'models' directory withinindir, so your images could for example be placed in a subfolder inside the training folder called 'predict'. Thus:Examplecelldeathpredict-path_predindir/predict/your/imgPredict optionscommanddescription-h, --helpshow this help message and exit-path_predPath where image/s to predict are stored.Version1.0.0AuthorsSantiago Miriuka|sgmiriuka@gmail.com|GitHub|twitterAlejandro La Greca|ale.lagreca@gmail.com|GitHub|twitterNelba Pérez|nelbap@hotmail.com|GitHub|twitterMore info and citationhttps://www.biorxiv.org/content/10.1101/2020.03.22.002253LicenseThis project is licensed under the MIT License - see theLICENSEfile for detailsAcknowledgmentsMeli and Shei.FLENIthe fastai team.