# External Model import in KNIME

**URL:** <https://forum.knime.com/t/external-model-import-in-knime/5085>\
**Category:** Node Development\
**Created:** [September 14, 2016, 10:51am UTC](https://forum.knime.com/t/external-model-import-in-knime/5085 "2016-09-14T10:51:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntonioGrieco](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@AntonioGrieco](https://forum.knime.com/u/AntonioGrieco)\
**Post date:** [September 14, 2016, 10:51am UTC](https://forum.knime.com/t/external-model-import-in-knime/5085/1 "2016-09-14T10:51:24Z")

</div>

&nbsp;

Good morning , I'm trying to import an external model KNIME . The model to be imported is generated by an external software KNIME and my goal is to import the node (thus indicate somehow the path where is the model) and write the model in another node. So I have to create a Learner node that take the model input and send it to a Predictor. I am attaching the code used , but the model is not imported it read . Forgive me if my English is wrong .

public class PROVA\_MODELNodeModel extends NodeModel {

private FISModel m\_model;

&nbsp;protected PROVA\_MODELNodeModel() {  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; // TODO: Specify the amount of input and output ports needed.  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;super(new PortType[] { BufferedDataTable.TYPE }, new PortType[] { PMMLPortObject.TYPE });  
&nbsp;&nbsp; &nbsp;  
&nbsp; &nbsp; }

&nbsp;

&nbsp; protected PortObject[] execute(final PortObject[] inData,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final ExecutionContext exec) throws Exception {  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;//&nbsp;&nbsp; &nbsp;logger.info("Node Model Stub... this is not yet implemented !");

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return new PortObject[] {(PortObject) m\_model};  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp; &nbsp; }

&nbsp;

&nbsp; &nbsp; @Override  
&nbsp; &nbsp; protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throws InvalidSettingsException {

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return new PortObjectSpec[] { null };  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}

&nbsp;

&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;/\*\*  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\* Solo il metodo saveModelContent deve essere sovrascritto, poiché non vi è&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\* Solo ModelOutport.  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\*&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\* @see De.unikn.knime.core.node.NodeModel # saveModelContent (int,&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\* De.unikn.knime.core.node.ModelContentWO)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\*/  
&nbsp; &nbsp; protected void saveModelContent(final int index,&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final ModelContentWO modelContent) throws InvalidSettingsException {  
&nbsp; &nbsp; &nbsp; &nbsp; m\_model.saveTo(modelContent);  
&nbsp; &nbsp; }

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

import org.knime.core.node.ModelContentWO;

public class FISModel {  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;public void saveTo(final ModelContentWO modelContent)  
&nbsp;&nbsp; &nbsp;{  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;modelContent.addModelContent("C:/Users/Antonio/Desktop/WM\_PERF615/Learner/LearnerFis.txtwm.fis");  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;}  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;

}

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [September 14, 2016, 2:13pm UTC](https://forum.knime.com/t/external-model-import-in-knime/5085/2 "2016-09-14T14:13:29Z")

</div>

I don't see any line that actually assign an object to m\_model. Therefore it's always null. In addition m\_model, which is a FISModel, is casted to PortObject but it clearly doesn't inherit from PortObject. So even if m\_model wasn't null you would get a ClassCastException.

I suggest you have a look at some existing nodes that output PortObjects. There are plenty in the base distribution.

&nbsp;

---

<div class="post-metadata">

**Author:** ![AntonioGrieco](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@AntonioGrieco](https://forum.knime.com/u/AntonioGrieco)\
**Post date:** [September 14, 2016, 2:36pm UTC](https://forum.knime.com/t/external-model-import-in-knime/5085/3 "2016-09-14T14:36:47Z")

</div>

Sorry for the stupid question but that I assign object m\_model ? I might have a link to some examples?

---

<div class="post-metadata">

**Author:** ![AntonioGrieco](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@AntonioGrieco](https://forum.knime.com/u/AntonioGrieco)\
**Post date:** [September 14, 2016, 2:41pm UTC](https://forum.knime.com/t/external-model-import-in-knime/5085/4 "2016-09-14T14:41:24Z")

</div>

```
So the type of output port is FISModel.TYPE and FisModel class call :

public class extends FisModelPortObject AbstractSimplePortObject {
public static final PortType TYPE = new PortType ( FisModelPortObject.class ) ;
```

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:21pm UTC](https://forum.knime.com/t/external-model-import-in-knime/5085/5 "2023-06-23T20:21:24Z")

</div>


