# Import Model

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

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

### Importing the Model

* Navigate to the ***Model*** tab.
* Click the ***Import Model*** option.

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FbQd3aTAYCQxVRsGPxsuw%2Fimage.png?alt=media&#x26;token=55079ebb-e90e-4153-981e-665b6de45959" alt=""><figcaption><p><em><strong>Using the Import Model option from the Model tab</strong></em></p></figcaption></figure>

* The user gets redirected to upload the model file.

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FoLBmV2fS5XHZ1YMWI4eD%2Fimage.png?alt=media&#x26;token=e453da17-e5f0-4815-bc9a-0227487c812b" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FOsaXLBI63mOlcSmdGncw%2Fimage.png?alt=media&#x26;token=503b511c-2da8-4c8e-823b-957d49712451" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> The Imported models are referred as **External models** in model list and they are marked with* <img src="https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/17Uw3vdUA4SVOX9RSdAS/image.png" alt="" data-size="line"> *as pre-fix to their names (as displayed in the above-given image)**.***&#x20;
{% endhint %}

### Exporting the Model to Data Pipeline

* The user can start a new Notebook with wrapper function that includes Data, Imported Model, Predict function, and output Dataset with predictions.

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FrwJKEcNQogOqvOEzRMLO%2Fimage.png?alt=media&#x26;token=49aa7456-0341-42f7-ab48-847423d97722" alt=""><figcaption></figcaption></figure>

* Register the Imported Model from the ***Models*** tab given on the Notebook page.

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FDDNqsWJdxMA72Yyr2lqK%2Fimage.png?alt=media&#x26;token=3c0dc820-f596-4ce1-b3aa-ed09470dd4b7" alt=""><figcaption></figcaption></figure>

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

&#x20;      ![](https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2Fmho9i5fFjJ566Rp35aRq%2Fimage.png?alt=media\&token=6e0afefd-afd7-4d4e-8f13-147a48280462)

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

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FFPRlNSORNqrWTrSfM3SR%2Fimage.png?alt=media&#x26;token=b2515754-a845-4f76-a288-8704dcbde6b6" alt=""><figcaption></figcaption></figure>

* Export the script using the ***Export*** functionality provided for the Notebooks on the ***Notebook List*** page.   &#x20;

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FL51gf7tQusGuCKapVO8l%2Fimage.png?alt=media&#x26;token=f83a3f63-5422-4c1e-9395-e38a43b58bae" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FGteyqkVyEnWLexAw4cxV%2Fimage.png?alt=media&#x26;token=6fd0e929-b90c-480e-a105-501bec32f02e" alt=""><figcaption></figcaption></figure>

* Click the ***Validate*** icon to validate the script.     &#x20;

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2F74cluEgj9PZwgX9TEK8l%2Fimage.png?alt=media&#x26;token=efc3381c-ff65-4895-87d5-dcf7e7ec63a8" alt=""><figcaption></figcaption></figure>

* A notification message appears to assure the validity of the script.
* Click the ***Export to Pipeline*** option.

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FH4a0NpOB1vwLS0DFk1cx%2Fimage.png?alt=media&#x26;token=8dba3ce9-ffbd-41f5-88ad-710eb7dd6200" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FbxJ0PiqK9khLbt7h7iZE%2Fimage.png?alt=media&#x26;token=1650b8be-d5c7-497d-9fe3-bc153c26cf96" alt=""><figcaption></figcaption></figure>

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

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

* Navigate to the ***Data Pipeline Workflow editor***.
* Drag the ***DS Lab Script Runner*** component and configure it.
* Select the ***script name*** from the drop-down option.
* The exported model along with the script can be accessed inside the ***Script Runner*** component.
* The user can connect the DS Lab Script Runner component to an Input Event.
* Run the Pipeline.    &#x20;

<figure><img src="https://2587201349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2FmGU89QNIi3LJsmH6xqqh%2Fimage.png?alt=media&#x26;token=1a341d60-bbc4-4c29-a70e-b6bfbe73ce68" alt=""><figcaption></figcaption></figure>

* The model predictions can be generated in the **Preview tab** of the connected Input Event.

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark> Only the **Exported Models** are accessed through the **DS Lab Script Runner** component, the other models can be accessed through the **Model Runner** component inside the Data Pipeline.*
{% endhint %}

<details>

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

Some of the Sample models and related scripts are provided below for the user to try his hands on this functionality. Please download them by a click, and use them in your Notebook by following the above mentioned steps.

</details>

### Sample files for Sklearn

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/Vegpl4UMCTIWEc3nn48u/SklearnModel.pkl>" %}
Sample Sklearn model for import.
{% endfile %}

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/PyAKcJc4kbOctGT30QNo/Importmodels_Sklearn_Inference.ipynb>" %}
Sample python script based on the imported Sklearn model.
{% endfile %}

### Sample files for Keras

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/6YMU5TpVnTNDTbwjvtNj/KersModel.h5>" %}
Sample Keras model for import.
{% endfile %}

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/FItRMwn2dsZUZ8AjaHNM/Importmodels_Keras_Inference.ipynb>" %}
Sample python script based on the imported Keras model.
{% endfile %}

### Sample files for PyTorch

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/V5NTuBTuqYVkx42PNvnC/Pytorch_Model.pth>" %}
Sample PyTorch model for import.
{% endfile %}

{% file src="<https://content.gitbook.com/content/BLGYLEkBUnc8nVEBAuEI/blobs/UUnhjYKJuiZHDHQJudAs/ImportModel_Pytorch_Inference.ipynb>" %}
Sample python script based on the imported PyTorch model.
{% endfile %}

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

* *The supported  extensions for External models - .pkl, .h5, .pth & .pt*
* *Refer the* [***Data Science Lab Quick Start Flow*** ](https://docs.bdb.ai/data-science-lab-3/data-science-lab-quick-start-flow)*page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
  {% endhint %}
