teamtma / Image_Captioning

MIT License
0 stars 0 forks source link

Final weights of CNN #1

Open tohiddar opened 2 years ago

tohiddar commented 2 years ago

How does the CNN here store the checkpoints and how can they be used to caption a new image without having to re-learn everytime?

tohiddar commented 2 years ago

Amirreze, now we can use this issue to track your progress on this task.

tohiddar commented 2 years ago

It looks like checkpoints are good for saving the model variable and useful for restarting a model from to continue to train it: "Checkpoints capture the exact value of all parameters (tf.Variable objects) used by a model. Checkpoints do not contain any description of the computation defined by the model and thus are typically only useful when source code that will use the saved parameter values is available." What we should be looking for is the SavedModel format which saves the model variables independent of the source code that created the model. SavedModel is ideal for model serving which is what I am after. Here is an intro to model serving: https://ubuntu.com/blog/guide-to-ml-model-serving @Amirreza-dar you should focus on savedmodels instead of checkpoints. We need to eventually update the code to incorporate the savedmodels approach.

tohiddar commented 2 years ago

Following the example of https://www.tensorflow.org/tfx/tutorials/serving/rest_simple , the command to save a model should look something like this. However, I am trying to find out what we should put instead of "model" in this part of the code that would correspond to the trained model for our image captioning analysis:

tf.keras.models.save_model( model, export_path, overwrite=True, include_optimizer=True, save_format=None, signatures=None, options=None )

tohiddar commented 2 years ago

@Amirreza-dar any updates on this task?

Amirreza-dar commented 2 years ago

I went through serving model example and here is what I got so far: In this example, they are using TensorFlow sequential which is a method for defining the configuration of neural network. In our case, we are defining these information in constructor function of both classes (CNN_encoder and RNN_decoder) in model.py. we can use TF sequential but since we have 2 NN we can't use tf.model_serving. I am trying to figure out a way to do it. this is the link to sequential: https://www.tensorflow.org/tfx/tutorials/serving/rest_simple

this is the part of code I'm talking about:

self.embedding = tf.keras.layers.Embedding(vocab_size, embedding_dim)
self.gru = tf.keras.layers.GRU(self.units,
                               return_sequences=True,
                               return_state=True,
                               recurrent_initializer='glorot_uniform')
self.fc1 = tf.keras.layers.Dense(self.units)
self.fc2 = tf.keras.layers.Dense(vocab_size)