<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MLFlow: How to load results from model and continue training in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7425#M352</link>
    <description>&lt;P&gt;@Tilo Wünsche​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To continue training an existing Keras/TensorFlow model that is stored in MLFlow, you need to follow the steps below:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Load the model from MLFlow using mlflow.keras.load_model method.&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE&gt;import mlflow.keras
&amp;nbsp;
model = mlflow.keras.load_model("model_uri")&lt;/CODE&gt;&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;Freeze the layers of the loaded model that you don't want to retrain.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for layer in model.layers[:-5]:
    layer.trainable = False&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the last five layers will be trainable and the rest of the layers will be frozen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Compile the model with the desired learning rate and optimizer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from tensorflow.keras.optimizers import Adam
&amp;nbsp;
optimizer = Adam(lr=0.0001)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the learning rate is set to 0.0001 and the Adam optimizer is used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Continue training the model with the new data. Use the fit method to continue training the model.&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE&gt;model.fit(new_X_train, new_y_train, epochs=10, batch_size=32, validation_data=(X_val, y_val))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the model is trained for 10 epochs with a batch size of 32.&lt;/P&gt;&lt;P&gt;With these steps, you should be able to load an existing Keras/TensorFlow model stored in MLFlow and continue training it with a different learning rate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2023 04:04:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-03-23T04:04:12Z</dc:date>
    <item>
      <title>MLFlow: How to load results from model and continue training</title>
      <link>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7424#M351</link>
      <description>&lt;P&gt;I'd like to continue / finetune training of an existing keras/tensorflow model. &lt;/P&gt;&lt;P&gt;We use MLFlow to store the model. How can I load the wieght from an existing model to the model and continue "fit" preferable with a different learning rate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just loading the model fails with some error, PyFuncModel does not provide the attributes and methods. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 15:20:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7424#M351</guid>
      <dc:creator>Tilo</dc:creator>
      <dc:date>2023-03-20T15:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: MLFlow: How to load results from model and continue training</title>
      <link>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7425#M352</link>
      <description>&lt;P&gt;@Tilo Wünsche​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To continue training an existing Keras/TensorFlow model that is stored in MLFlow, you need to follow the steps below:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Load the model from MLFlow using mlflow.keras.load_model method.&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE&gt;import mlflow.keras
&amp;nbsp;
model = mlflow.keras.load_model("model_uri")&lt;/CODE&gt;&lt;/PRE&gt;&lt;OL&gt;&lt;LI&gt;Freeze the layers of the loaded model that you don't want to retrain.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for layer in model.layers[:-5]:
    layer.trainable = False&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the last five layers will be trainable and the rest of the layers will be frozen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Compile the model with the desired learning rate and optimizer.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from tensorflow.keras.optimizers import Adam
&amp;nbsp;
optimizer = Adam(lr=0.0001)
model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the learning rate is set to 0.0001 and the Adam optimizer is used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Continue training the model with the new data. Use the fit method to continue training the model.&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE&gt;model.fit(new_X_train, new_y_train, epochs=10, batch_size=32, validation_data=(X_val, y_val))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this example, the model is trained for 10 epochs with a batch size of 32.&lt;/P&gt;&lt;P&gt;With these steps, you should be able to load an existing Keras/TensorFlow model stored in MLFlow and continue training it with a different learning rate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 04:04:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7425#M352</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-23T04:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: MLFlow: How to load results from model and continue training</title>
      <link>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7426#M353</link>
      <description>&lt;P&gt;Basically you covered all what is needed for retrain model. &lt;/P&gt;&lt;P&gt;One thing that is good to mention is that if @Tilo Wünsche​&amp;nbsp; use DBR runtime 12.x .mlflow updated to version 2.x which throw an error if using mlflow.keras. ( No moudle names mlflow.keras)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from my point of view  all remain the same, just use mlflow.tensorflow.load_model instead&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 08:24:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7426#M353</guid>
      <dc:creator>Orianh</dc:creator>
      <dc:date>2023-03-23T08:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: MLFlow: How to load results from model and continue training</title>
      <link>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7427#M354</link>
      <description>&lt;P&gt;Hi @Tilo Wünsche​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We'd love to hear from you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 06:29:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/mlflow-how-to-load-results-from-model-and-continue-training/m-p/7427#M354</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-27T06:29:26Z</dc:date>
    </item>
  </channel>
</rss>

