> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-science-lab-6/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bdb.ai/data-science-lab-6/tabs-for-a-dsl-project/model/import-model.md).

# Import Model

External models can be imported into the Data Science Lab and experimented inside the Notebooks using the Import Model functionality.

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*&#x20;

* *The External models can be registered to the **Data Pipeline** module and inferred using the Data Science Lab script runner.*
* Only the **Native prediction functionality** will work for the External models.
  {% endhint %}

### Importing a Model

{% hint style="success" %}
*Check out the illustration on importing a model.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FGKNnJI3mDu2fPV7FdAPc%2FImporting%20a%20model%20(sklearn).mp4?alt=media&token=3fe7fd0f-d6be-4905-a9d2-8ffeb23ea7ef>" %}
***Importing a Model***
{% endembed %}

* Navigate to the ***Model*** tab for a Data Science Project.
* Click the ***Import Model*** option.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/1Oso9XoCRHY8BNxNr2ev/image.png" alt=""><figcaption></figcaption></figure>

* The user gets redirected to upload the model file. Select and upload the file.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/tvIvwoinHNGBkUQfz4NB/image.png" alt=""><figcaption></figcaption></figure>

* A notification message appears.
* The imported model gets added to the model list.&#x20;

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/w0apMCgTWGhZzVqrqFAO/image.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> The imported models are referred to as **External models** in the model list and are marked with a prefix to their names (as displayed in the above-given image)**.***&#x20;
{% endhint %}

### Exporting a Model to the Data Pipeline

You can integrate and export cutting-edge Data Science models into your data pipeline, ensuring optimized performance, real-time insights, and data-driven decision-making. The user needs to start a new .ipynb file with a wrapper function that includes Data, Imported Model, Predict function, and output Dataset with predictions.

* Navigate to a Data Science Notebook (.ipynb file) from an activated project. In this case, a notebook has been imported with the wrapper function.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/3075AY24bUg7Ku3Kzh5v/image.png" alt=""><figcaption></figcaption></figure>

* Access the Imported Model inside this .ipynb file.
* Load the imported model to the Notebook cell.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/lUNbCWIPp4BGnQiquia2/image.png" alt=""><figcaption></figcaption></figure>

* Mention the loaded model in the inference script.
* Run the code cell with the inference script.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/Ie3rAySn2GALnqFjltwR/image.png" alt=""><figcaption></figcaption></figure>

* The Data preview is displayed below.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/B8VVVDB3O0trhdtc03e4/image.png" alt=""><figcaption></figcaption></figure>

* Click the ***Register*** option for the imported model from the ellipsis context menu.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/XrQkeRvbE2bTnW7t79lV/image.png" alt=""><figcaption></figcaption></figure>

* The ***Register Model*** dialog box appears to confirm the model registration.
* Click the ***Yes*** option.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/O7IezhMMskwvQnNwCMXp/image.png" alt=""><figcaption></figcaption></figure>

* A notification message appears, and the model gets registered.   &#x20;

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/hpJDgYsUbkqXykaUcAwf/image.png" alt=""><figcaption></figcaption></figure>

* Export the script using the ***Export*** functionality provided for the Data Science Notebook (.ipynb file).     &#x20;

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/XCTH7HncUWk3IrYgVySC/image.png" alt=""><figcaption></figcaption></figure>

* Another notification appears to ensure that the Notebook is saved.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/OqCdeDp9ltM3iv5u7tsc/image.png" alt=""><figcaption></figcaption></figure>

* The ***Export to Pipeline*** window appears.
* Select a specific script from the Notebook. or Choose the ***Select All*** option to select the full script.
* Select the ***Next*** option. &#x20;

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/amuRnGHR4QTtXXEljUFc/image.png" alt=""><figcaption></figcaption></figure>

* Click the ***Validate*** icon to validate the script.     &#x20;
* A notification message appears to ensure the validity of the script.
* Click the ***Export to Pipeline*** option.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/cCUlErx9RLSmKe6KzEaE/image.png" alt=""><figcaption></figcaption></figure>

* A notification message appears to ensure that the selected Notebook has been exported.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/NqUoKOr3WMvBwQbVg3wh/image.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> The imported model gets registered to the Data Pipeline module as a script.*
{% endhint %}

### Accessing the Exported Model within the Pipeline User interface

* Navigate to the ***Data Pipeline Workflow editor***.
* Drag the ***DS Lab Runner*** component and configure the Basic Information.
* Open the Meta Information tab of the DS Lab Runner component.
* Configure the following information for the ***Meta Information*** tab.&#x20;
  * Select ***Script Runner*** as the ***Execution Type.***&#x20;
  * Select function input type.
  * Select the project name.
  * Select the ***Script Name*** from the drop-down option. The same name given to the imported model appears as the script name.
  * Provide details for the External Library (if applicable).
  * Select the Start Function from the drop-down menu.
* The exported model can be accessed inside the ***Script** section*.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/mGxB1DC2FQZCQclNlj4Y/image.png" alt=""><figcaption></figcaption></figure>

* The user can connect the DS Lab Script Runner component to an Input Event.
* Run the Pipeline.    &#x20;
* The model predictions can be generated in the **Preview tab** of the connected Input Event.

<figure><img src="https://content.gitbook.com/content/28ipFzCz8EMtVtHrBFLx/blobs/QFo9duWmwNJ9v1Yx9iY2/image.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*&#x20;

* *The **Imported Models** can be accessed through the **Script Runner** component inside the Data Pipeline module.*
* *The execution type should be Model Runner inside the Data Pipeline while accessing the other exported Data Science models.*
* *The supported  extensions for External models - .pkl, .h5, .pth & .pt*
  {% endhint %}

<details>

<summary>Try out the Import Model Functionality yourself</summary>

Some of the Sample models and related scripts are provided below for the users to try this functionality. Please download them with a click, and use them inside your Data Science Notebook by following the above-mentioned steps.

</details>

### Sample files for Sklearn

{% file src="/files/0zWLNiIM0knm1qNeBb3o" %}
Sample Sklearn model for import.
{% endfile %}

{% file src="/files/7Ebha1DYu6jigqia6mJL" %}
Sample python script based on the imported Sklearn model.
{% endfile %}

### Sample files for Keras

{% file src="/files/wNVs6i2rgzgOk3JMDGXc" %}
Sample Keras model for import.
{% endfile %}

{% file src="/files/y5OpsUy8n362KAsROtFv" %}
Sample python script based on the imported Keras model.
{% endfile %}

### Sample files for PyTorch

{% file src="/files/7j7r5cBD4mTp3C8rQEuj" %}
Sample Pytorch model for import
{% endfile %}

{% file src="/files/NcEagGQoee6yw7QAcJrm" %}
Sample python script based on the imported Pytorch model.
{% endfile %}
