How to use TensorFlow Hub with code examples

None of the image augmentation modules (at the time of writing) have any variables in them, and consequently, these modules are not fine-tunable/trainable. Using the signature of ‘from_decoded_images’, you can directly feed the images to these module. An example code block along with the generated augmented images is shown below.Image Augmentation ModuleAugmented ImagesThe real utility of image augmentation comes when you club this module with other modules from image classification, feature vector, etc in your pipeline. In the previously trained multi-label animal attribute classification problem using Feature Vector module, I have added crop_color image augmentation module, and with the same number of epochs, my F1 score improves to 0.96244. In this code example, I make use of default signature, which will expect the image in encoded form as its input. Now, as my image augmentation module resizes the input image to a fixed size for further processing by Resnet50 module, I have saved the work of explicitly resizing the images myself which I had done previously.Image Augmentation module clubbed with other moduleYou can also check my previously written article on image augmentation covering the basic types of augmentations.6) Object Detection ModulesObject detection modules do not support fine-tuning, so you will have to perform training from scratch if you have your own dataset. Batching of the data is also not supported at the moment. In the code example, I will be only performing inference on the images using FasterRCNN on Inception-ResNet V2 module. I have enclosed the module part of code and images generated from the module below.Object Detection Module of TensorFlow HubObject Detetion Module7) Generator ModulesThese correspond to Generative Adversial Networks(GAN)..Some of the modules have not exposed their Discriminator part of the network..Just like object detection, even here in code sample, I will be just performing inference..Using the Progressive GANs module which is trained on CelebA dataset, I will be generating new faces..I have enclosed the module part of code and images generated from the module below.Generator module of Tensorflow HubImages generated from Progressive GANs of Generator ModuleIf you would like to see the complete code integrated with Dataset and Iterators, and saved with Saved_Model, you can check out the code in my GitHub repository.Prasad9/TFHubSampleDemonstration of usage of different types of TensorFlow Hub modules integrated with Datasets, Iterators and…github.comIf you would like to read more about Dataset and Iterators of TensorFlow along with code examples, you can read about them in my another Medium post.How to use Dataset and Iterators in Tensorflow with code samplesFrom the time I have started using Tensorflow, I have always been feeding the data to my graph during training, testing…medium.comLastly, do let me know your thoughts about this article through comments section.. More details

Leave a Reply