> For the complete documentation index, see [llms.txt](https://docs.bdb.ai/data-science-lab-5/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-5/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://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FKy7YdH0xmrYWnIh0QgYt%2Fimage.png?alt=media&amp;token=69b7e789-46e7-4d5c-af66-e0d384daf619" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FlLTV1zNt0FLMmPcCDgAq%2Fimage.png?alt=media&amp;token=d5c79804-efd2-4c4d-8c10-77a0c00e2f3d" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FVjmSCpxzZha9mpvVCN8q%2Fimage.png?alt=media&amp;token=39b03189-243d-4e2c-b902-2c7d8b4b9455" 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 pre-fix to their names (as displayed in the above-given image)**.***&#x20;
{% endhint %}

### Exporting the Model to the Data Pipeline

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.

{% hint style="success" %}
*Check out the walk-through on Export to Pipeline Functionality for a model.*
{% endhint %}

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FmUXgQRe9UOsl3FljFa1C%2Fimage.png?alt=media&amp;token=1b5ee018-18d2-4b4c-ad1a-6dd87ee9162f" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2Fy0l93a9f678ymfyszuDC%2Fimage.png?alt=media&amp;token=e4293eff-f6b7-4370-ac09-bdb5a3cc2794" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F3OMIbgMOwYMHpf6T8KE8%2Fimage.png?alt=media&amp;token=832ea4ce-0b28-4402-8e07-573aeea6e18e" alt=""><figcaption></figcaption></figure>

* The Data preview is displayed below.

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FSHxAcKi3dPRC414ev7LO%2Fimage.png?alt=media&amp;token=bd9c3508-997a-48e5-9704-c5b5f76bc44c" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F6gHR9pJHKJPs8jGRJNLU%2Fimage.png?alt=media&amp;token=bece15f8-4c36-4e29-b0c9-61d5f8427e58" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F4Cfmg1tp59KzXhRkKf9Z%2Fimage.png?alt=media&amp;token=c641cce9-beb7-4997-96af-0782d0d105fd" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FfnJhUXo8tYPGvVFLryuU%2Fimage.png?alt=media&amp;token=ff471030-8a07-4544-99d9-8f9269e4be90" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2Fd7vMHtmaLexrdafBa8Jk%2Fimage.png?alt=media&amp;token=4ff992c6-7c82-4de0-856c-93f90ad63843" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FUfeqAvztZDLtrFQpqX8d%2Fimage.png?alt=media&amp;token=cfe28cc6-39fe-4709-a232-c6d4d167a594" 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://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F6Qo0uViqdOhnzMbsvoUN%2Fimage.png?alt=media&amp;token=5812ab9f-5def-49ea-bbe4-e65ec5d266b3" 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://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F4T0gG5pKTwyrjpsD1nic%2Fimage.png?alt=media&amp;token=47e2a644-095c-402e-80fa-7039770683ce" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2Fuv5JGGeGk2VYDy1UAswH%2Fimage.png?alt=media&amp;token=2c0595c1-4139-4e6d-a7dc-2db891c48963" 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://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2F8FYIH0z1exFcR1gd7gSj%2Fimage.png?alt=media&amp;token=b37f61e1-0bba-4f74-8718-fbda98dede36" 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://3817372244-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz33KQNYQvBTgQKJBgwTz%2Fuploads%2FWiEBjYcmq7PJMYmiYhW2%2Fimage.png?alt=media&amp;token=4e00e248-8da5-4e64-a8b2-03f815228103" 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 %}
