| package org.eclipse.papyrus.aiml.gen.keras |
| |
| import org.eclipse.papyrus.aiml.profile.AIML.Recurrent_layers.Recurrent_layers |
| |
| class RecurrentLayerOps { |
| |
| |
| static def lstmAttributesToDisplay (Recurrent_layers lay_val){ |
| var t = RecurrentLayerOps.lstmAttributesToCollect(lay_val) |
| var attributesNameList=t.attributeNames.toList |
| var attributesValueList=t.attributeValues.toList |
| |
| |
| var String DisplayInit="self."+lay_val.base_Class.name+"=tf.keras.layers."+lay_val.eClass.name // example : self.lstm1=tf.keras.layers.LSTM |
| |
| var Display = "" // Initialization an empty String variable |
| var modificationState=0 |
| var in=0 |
| for(step : attributesValueList){ |
| if( attributesNameList.get(in).equals("hidden_size")){ |
| System.err.println(step) |
| var String DisplayHiddenSize = step+',' |
| Display+=DisplayHiddenSize //à verifier += au lieu de d=d+a |
| modificationState++ |
| |
| } |
| in+=1 |
| } |
| |
| var ind =0 |
| for(step : attributesValueList){ |
| |
| if( GenCheck.isZeroForStringL(step) || GenCheck.isNullOrEmptyForString(step) || GenCheck.isFalseForString(step) ){ |
| |
| //System.out.print("Rejected : "+attributesNameList.get(ind)+" = "+step+"\n") |
| |
| }else{ |
| //System.out.print("Valid : "+attributesNameList.get(ind)+" = "+step+"\n") |
| |
| if(attributesNameList.get(ind).equals("name") || attributesNameList.get(ind).equals("hidden_size") || attributesNameList.get(ind).equals("num_layers")){ |
| }else{ |
| if(!attributesNameList.get(ind).endsWith("_pt")){ //filter PyTorch specific attributes |
| |
| |
| modificationState++ |
| if(step.equals("true") || step.equals("false") ){ // correct Boolean value to python boolean with MAJ |
| var String DisplayInit1 = attributesNameList.get(ind) |
| |
| if(step.equals("false")){ |
| var newstep = "F"+step.substring(1, step.length()) |
| var String DisplayStateZero1 = DisplayInit1+'='+newstep+',' |
| Display=Display+DisplayStateZero1 |
| |
| }else{ |
| var newstep = "T"+step.substring(1, step.length()) |
| var String DisplayStateZero2 = DisplayInit1+'='+newstep+',' |
| Display=Display+DisplayStateZero2 |
| } |
| |
| }else if(attributesNameList.get(ind).equals("input_size")){ |
| var String DisplayInit3 = "input_shape" |
| var String DisplayStateZero3 = DisplayInit3+'=['+step+'],' |
| Display=Display+DisplayStateZero3 |
| |
| }else{ |
| var String DisplayInit0 = attributesNameList.get(ind) |
| var String DisplayStateZero0 = DisplayInit0+'='+step+',' |
| Display=Display+DisplayStateZero0 |
| } |
| } |
| } |
| } |
| ind = ind + 1 |
| } |
| |
| var displayFinal="" |
| |
| if (modificationState!=0){ |
| displayFinal=DisplayInit+"("+Display.substring(0, Display.length() - 1)+")" |
| }else{ |
| displayFinal=DisplayInit //Non optimal _ recuperer la valeur |
| } |
| |
| return displayFinal |
| } |
| |
| static def lstmAttributesToCollect (Recurrent_layers lay_val){ |
| |
| val nbrOfAttributes=lay_val.eClass.EAllAttributes.length // Get the quantity of attributes |
| |
| var layerInformations = new LayerInfo(nbrOfAttributes) // Call LayerInformation Constructor to build 2D Array |
| |
| var attributesNameList = layerInformations.attributeNames // Dispatch attributesNames from LayerInformation in a List |
| var attributesValueList = layerInformations.attributeValues // Dispatch attributesValues from LayerInformation in a List |
| |
| var l=0 // Index initialization for the incremental loop |
| for (valu : lay_val.eClass.EAllAttributes){ // Loop which will collect Attribute Names and Attribute Values for Layers |
| |
| var attri_name=valu.name // Variable instance for attribute name for each elements in the loop |
| attributesNameList.set(l,attri_name) // Add attribute name in the list |
| |
| var attri_val=lay_val.eGet(valu) // Variable instance for attribute values for each elements in the loop and String conversion |
| attributesValueList.set(l,String.valueOf(attri_val)) // Add attribute value in the list |
| |
| l=l+1 // Index incrementation +1 during loop |
| |
| } |
| return layerInformations // return LayerInfo object [Name,Value] |
| } |
| } |