Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix
Python script can be used to train a Convolutional Neural Network (CNN) for indexing Transmission Electron Microscopy (TEM) electron diffraction patterns. This includes data preprocessing, model creation (using EfficientNet-B3), and training with evaluation metrics like accuracy and F1 score. For instance, ImageDataGenerator in TensorFlow/Keras can be used to augment the images during training. EfficientNetB3 can be used as the base model, with the top layers removed and a custom head added for classification. The model can be compiled with the Adam optimizer and categorical cross-entropy loss. Early stopping and model checkpointing are then applied to prevent overfitting and save the best model. On the other hand, to do indexing, a dataset of TEM diffraction patterns, with labels indicating the correct classes, is needed. Forthermore, the data needs to be organized in a directory structure that is compatible with the ImageDataGenerator in TensorFlow/Keras as shown in Figure 941a.
The Root Directory is the top-level directory that contains all the data, which is split into three subdirectories: train, val, and test. Inside each of the train, val, and test directories, there should be subdirectories named according to the classes (e.g., class1, class2, etc.). Each class subdirectory contains images that belong to that class. The images should be in a format that can be read by TensorFlow, such as .jpg, .jpeg, .png, etc. Each image should be placed in the appropriate class subdirectory depending on which class it belongs to. Each subdirectory contains images belonging to that specific class, and the model will learn to classify images based on this structure. However, the file names of the images within each class directory can be anything, as long as they are unique within that directory. This directory structure allows ImageDataGenerator to automatically label the data based on the directory names (class names) and create batches of images for training, validation, and testing. Finally, the model is evaluated on a test dataset, and accuracy and F1 score are calculated, and a classification report provides precision, recall, and F1 score for each class.
|