Package: tlearner
AboutWe provide a set of transfer learning-based model training and evaluation functions. ImageNet pretrained weights are used.The series of Efficient Net models are supported.
There is always a trade-off between model size and accuracy. Our guideline is as follows:For tfjs apps, use EfficientNetB0 or EfficientNetB1; For tf-lite apps, use EfficientNetB2 ~ B4; For desktop apps, use EfficientNetB5 and above.The following table is from keras website:ModelSize (MB)Top-1 AccuracyTop-5 AccuracyParametersDepthTime (ms) per inference step (CPU)Time (ms) per inference step (GPU)Xception8879.0%94.5%22.9M81109.48.1VGG1652871.3%90.1%138.4M1669.54.2VGG1954971.3%90.0%143.7M1984.84.4ResNet509874.9%92.1%25.6M10758.24.6ResNet50V29876.0%93.0%25.6M10345.64.4ResNet10117176.4%92.8%44.7M20989.65.2ResNet101V217177.2%93.8%44.7M20572.75.4ResNet15223276.6%93.1%60.4M311127.46.5ResNet152V223278.0%94.2%60.4M307107.56.6InceptionV39277.9%93.7%23.9M18942.26.9InceptionResNetV221580.3%95.3%55.9M449130.210.0MobileNet1670.4%89.5%4.3M5522.63.4MobileNetV21471.3%90.1%3.5M10525.93.8DenseNet1213375.0%92.3%8.1M24277.15.4DenseNet1695776.2%93.2%14.3M33896.46.3DenseNet2018077.3%93.6%20.2M402127.26.7NASNetMobile2374.4%91.9%5.3M38927.06.7NASNetLarge34382.5%96.0%88.9M533344.520.0EfficientNetB02977.1%93.3%5.3M13246.04.9EfficientNetB13179.1%94.4%7.9M18660.25.6EfficientNetB23680.1%94.9%9.2M18680.86.5EfficientNetB34881.6%95.7%12.3M210140.08.8EfficientNetB47582.9%96.4%19.5M258308.315.1EfficientNetB511883.6%96.7%30.6M312579.225.3EfficientNetB616684.0%96.8%43.3M360958.140.4EfficientNetB725684.3%97.0%66.7M4381578.961.6EfficientNetV2B02978.7%94.3%7.2M---EfficientNetV2B13479.8%95.0%8.2M---EfficientNetV2B24280.5%95.1%10.2M---EfficientNetV2B35982.0%95.8%14.5M---EfficientNetV2S8883.9%96.7%21.6M---EfficientNetV2M22085.3%97.4%54.4M---EfficientNetV2L47985.7%97.5%119.0M---Installpip install tensorflow-gpu >= 2pip install tlearnerHow to useInitializefrom tlearner.efficientnet import transfer_learner
learner = transfer_learner("my_model", W = 224) # my_model.h5df will be the model nameLoad datalearner.load_dataset('my_data_folder', PKL_PATH = "my_dataset.pkl") # Images in each subfolder of my_data_folder are treated as one class. If PKL_PATH is specified, a pkl that contains X_train, y_train, X_val, y_val, etc. will be generated.print(learner.class_names) # print class namesTrain a new modelhist = learner.train_custom_model("EfficientNetB1", batch = 8, epochs = [10,0], optimizer = "adam") # EfficientNetB0-B7 can be used.plot_history(hist) # plot training curvesEvaluatelearner.evaluate(N = 30) # predict the first N samples in X_valPredictlearner.predict_file('my_image.jpg')Convert [Optional]learner.convert_to_tflite(v1 = True) # convert to a local tflite modelLoad an existing modellearner.load_best_model() # if you have an existing local modellearner.get_best_model().summary() # print model architecturelearner.plot_best_model() # save model architecture to a local image fileJupyter notebooksUnder /notebooks, we provide two examples. One is flower image classification; the other is fundus image classification.DeploymentAfter training, you will get a keras h5 model file. You can further convert it to tflite format, or tfjs format (efficient net is not supported yet).Then you can deploy on mobile device or browser-based apps.