I am trying to implement Neural Style Transfer using TensorFlow and want to integrate the same within an Android application for image filtering. Can anyone help me save this TensorFlow model, so I can restore it whenever in use in the application?
I've tried creating .ckpt file of this TensorFlow model, but I'm not able to create one.
I haven't copied the code here as it consists of dozens of lines. Here is the link for the model https://colab.research.google.com/github/tensorflow/models/blob/master/research/nst_blogpost/4_Neural_Style_Transfer_with_Eager_Execution.ipynb
I am expecting to save this model to generate a new image at very low latency. Currently, I've to run hundreds of iterations for every image and that's what I don't want in real time while running in the application.
Related
I am training a model with a huge dataset and creating it every time is a huge hassel so I was wondering if there is a way to download the model and reuse it rather than creating and running it repeatedly everytime i use it. (i am a beginner)
i am expecting to download this model and use it multiple times rather than start from scratch then build and train it.
I have defined a deep learning model my_unet() in tensorflow. During training I set save_weigths=False since I wanted to save the entire model (not only the wieghts bu the whole configuration). The generated file is path_to_model.hdf5.
However, when loading back the model I used the earlier version (I forgot to update it) in which I first called the model and then load the model using:
model = my_unet()
model.load_weights(path_to_model.hdf5)
Instead of simply using: model = tf.keras.models.load_model(path_to_model.hdf5) to load the entire model.
Both ways of loading the model and the weights provided the same predictions when run in some dummy data and there were no errors.
My question is: Why loading the entire model using model.load_weights() does not generate any problem? What is the structure of the hdf5 file and how theese two ways of loading exactly work? Where can I find this information?
You can please see the documentation here for any future reference: http://davis.lbl.gov/Manuals/HDF5-1.8.7/UG/03_DataModel.html
I'm currently using TensorFlow and KERAS on PyCharm. Every time I want to use a model I have to run the training data again then in the same script then run the testing data. How would I run the training data once, and then I can go on whenever I want and run testing data through the model and it will still work. Ie. Developing a model to recognise images, how would I run the program whenever I want to recognise images, instead of having to run the training data and then recognise images in the same script.
You can do that, by saving and then loading your model.
Here's a link to the documentation:
https://www.tensorflow.org/tutorials/keras/save_and_load
Saving and loading only the weights will make this process more efficient if you already have the structure in your code that makes the prediction. So you might want to look into that too.
I've been using this tutorial from TensorFlow's site to create a script (python3) that performs a style transfer. I'm trying to train a model on a particular art piece and then apply that style to any random photo. From my understanding of this tutorial the script takes a style image and a content image, runs them through the VGG19 model and spits out a final image (takes about 30min on my machine). But I see no way to save the trained model to apply it to another content photo. This tutorial doesn't use TF's model fit(), predict(), and save() methods like I would expect. It just seems to be applying the prediction to the image as it trains.
How do I save the trained model? Once saved how do I use it on another content photo?
Use model.save() method.
Read this tutorial: https://www.tensorflow.org/guide/keras/save_and_serialize
I want to fine tune existing OpenCV DNN face detector to a face images database that I own. I have opencv_face_detector.pbtxt and opencv_face_detector_uint8.pb tensorflow files provided by OpenCV. I wonder if based on this files is there any way to fit the model to my data? So far, I haven't also managed to find any tensorflow training script for this model in OpenCV git repository and I only know, that given model is and SSD with resnet-10 as a backbone. I am also not sure, reading the information on the internet, if I can resume training from .pb file. Are you aware of availability of any scripts defining the model, that could be used for training? Would pbtxt and pb files be enough to continue training on new data?
Also, I noticed that there is a git containing caffe version of this model https://github.com/weiliu89/caffe/tree/ssd. Although I never worked with caffe before, would it be possible/easier to use existing weight (caffe .pg and .pbtxt files are also available in OpenCV's github) and fit the model to my dataset?
I don't see a way to do this in opencv, but I think you'd be able to load the model into tensorflow and use model.fit() to retrain.
The usual advice about transfer learning applies. You'd probably want to freeze most of the early layers and only retrain the last one or two. A slow learning rate would be advised as well.