Keras and LSTM configuration problem
I am experiencing problem configuring Keras/LSTM model. I get the following error dueing execution
Execution of Python script failed
Please check your Python script: ValueError:
Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (212, 41) (script, line 295)
LayerListIOObject
LSTM(41, input_shape=var_input_shape, batch_input_shape=(1, 2, 17), activation='tanh', recurrent_activation='tanh', use_bias=True, kernel_initializer=glorot_uniform(seed=None), recurrent_initializer=glorot_uniform(seed=None), bias_initializer=Zeros(), unit_forget_bias=True, kernel_regularizer=None,recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, stateful=True, unroll=False, implementation=0),
Dense(2, activation='softmax', use_bias=True, kernel_initializer=glorot_uniform(seed=None), bias_initializer=Zeros(), kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)
<?xml version="1.0" encoding="UTF-8"?><process version="8.0.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="8.0.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="read_excel" compatibility="8.0.001" expanded="true" height="68" name="Read Excel" width="90" x="45" y="34">
<parameter key="excel_file" value="C:\Users\ipasha\.RapidMiner\repositories\Local Repository\TextMining\Data\State.xlsx"/>
<list key="annotations"/>
<list key="data_set_meta_data_information"/>
</operator>
<operator activated="true" class="set_role" compatibility="8.0.001" expanded="true" height="82" name="Set Role" width="90" x="179" y="34">
<parameter key="attribute_name" value="PortState"/>
<parameter key="target_role" value="label"/>
<list key="set_additional_roles">
<parameter key="PortState" value="label"/>
</list>
</operator>
<operator activated="true" class="split_data" compatibility="8.0.001" expanded="true" height="103" name="Split Data" width="90" x="313" y="187">
<enumeration key="partitions">
<parameter key="ratio" value="0.9"/>
<parameter key="ratio" value="0.1"/>
</enumeration>
</operator>
<operator activated="true" class="keras:sequential" compatibility="1.0.003" expanded="true" height="166" name="Keras Model" width="90" x="447" y="34">
<parameter key="input shape" value="(41,)"/>
<parameter key="loss" value="sparse_categorical_crossentropy"/>
<parameter key="optimizer" value="Adam"/>
<enumeration key="metric"/>
<parameter key="epochs" value="128"/>
<enumeration key="callbacks">
<parameter key="callbacks" value="TensorBoard(log_dir='./logs', histogram_freq=0, write_graph=True, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)"/>
</enumeration>
<process expanded="true">
<operator activated="true" class="keras:recurrent_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Recurrent Layer" width="90" x="112" y="34">
<parameter key="layer_type" value="LSTM"/>
<parameter key="no_units" value="41"/>
<parameter key="recurrent_activation" value="tanh"/>
<parameter key="stateful" value="true"/>
</operator>
<operator activated="true" class="keras:core_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Core Layer (2)" width="90" x="447" y="34">
<parameter key="no_units" value="2"/>
<parameter key="activation_function" value="'softmax'"/>
<parameter key="dims" value="1.1"/>
</operator>
<connect from_op="Add Recurrent Layer" from_port="layers 1" to_op="Add Core Layer (2)" to_port="layers"/>
<connect from_op="Add Core Layer (2)" from_port="layers 1" to_port="layers 1"/>
<portSpacing port="sink_layers 1" spacing="0"/>
<portSpacing port="sink_layers 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="keras:apply" compatibility="1.0.003" expanded="true" height="82" name="Apply Keras Model" width="90" x="581" y="187"/>
<connect from_op="Read Excel" from_port="output" to_op="Set Role" to_port="example set input"/>
<connect from_op="Set Role" from_port="example set output" to_op="Split Data" to_port="example set"/>
<connect from_op="Split Data" from_port="partition 1" to_op="Keras Model" to_port="training set"/>
<connect from_op="Split Data" from_port="partition 2" to_op="Apply Keras Model" to_port="unlabelled data"/>
<connect from_op="Keras Model" from_port="model" to_op="Apply Keras Model" to_port="model"/>
<connect from_op="Apply Keras Model" from_port="labelled data" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
What configuration change do I need to fix this problem?
Thanks
Answers
hello @ipasha - welcome to the community. I'm tagging our Keras guru @jpuente in hopes he has time to respond.
Scott
Thanks Scott. I am still waiting for a response from the Keras guru @jpuente!
@jpuente is a busy guy. It's not easy being a guru.
Maybe @jacobcybulski or @dgrzech or @M_Martin or @pschlunder have a moment?
Scott
Hi,
you're defining a wrong input_shape. Recurrent layers await (time)steps and the data sets input dimension as an input.
Please checkout the included s&p 500 regression examples of the RapidMiner Keras Operator. It uses Conv Layers but works very similar.
We also have a recorded webinar on using the extension, you can find the recording as well as the slide deck here:
https://rapidminer.com/resource/state-deep-learning/
Some additional resources to check out:
https://keras.io/getting-started/sequential-model-guide/#specifying-the-input-shape
https://keras.io/layers/recurrent/#rnn
Regards,
Philipp
You might like the following link to a PDF-document that includes all slides from RapidMiner's Philipp Schlunder.
This PDF includes:
I couldn't find this PDF on RapidMiners site. Also, the video from Philipp is truncated, it doesn't show the explanation of the examples. I, therefore, found this PDF very useful.
Philipp Schlunder presentation
@pschlunder @luc_bartkowski @jpuente
Hello,
I am trying to apply Recurrent Network with simple RNN. I am encountering issue with input dimensions. The error states that expected simple_rnn_1 input to have 3 dimensions but got an array of shape (1029,408). I gave input shape of keras model as (1,408) where 1 is the time step and 408 is the number of attributed in my dataset. Batch size is 10. But still I am unable to understand why I am encountering this issue. Your help is much appreciated. Please find XML code below.
<?xml version="1.0" encoding="UTF-8"?><process version="8.2.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="8.2.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="retrieve" compatibility="8.2.000" expanded="true" height="68" name="Retrieve_2_Clip_ORG_CB_T2" width="90" x="45" y="85">
<parameter key="repository_entry" value="2_Clip_ORG_CB_T2"/>
</operator>
<operator activated="true" class="concurrency:cross_validation" compatibility="8.2.000" expanded="true" height="145" name="Cross Validation" width="90" x="380" y="34">
<parameter key="number_of_folds" value="5"/>
<process expanded="true">
<operator activated="true" class="keras:sequential" compatibility="1.0.003" expanded="true" height="166" name="Keras Model" width="90" x="179" y="34">
<parameter key="input shape" value="(1,408)"/>
<parameter key="optimizer" value="Adam"/>
<enumeration key="metric"/>
<parameter key="epochs" value="20"/>
<parameter key="batch size" value="10"/>
<enumeration key="callbacks"/>
<process expanded="true">
<operator activated="true" class="keras:recurrent_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Recurrent Layer" width="90" x="313" y="34">
<parameter key="no_units" value="200"/>
<parameter key="activation" value="relu"/>
<parameter key="dropout" value="0.3"/>
<parameter key="recurrent_dropout" value="0.3"/>
</operator>
<operator activated="true" class="keras:core_layer" compatibility="1.0.003" expanded="true" height="82" name="Add Core Layer" width="90" x="447" y="34">
<parameter key="no_units" value="2"/>
<parameter key="activation_function" value="'softmax'"/>
<parameter key="target_shape" value="2"/>
<parameter key="dims" value="1.1"/>
</operator>
<connect from_op="Add Recurrent Layer" from_port="layers 1" to_op="Add Core Layer" to_port="layers"/>
<connect from_op="Add Core Layer" from_port="layers 1" to_port="layers 1"/>
<portSpacing port="sink_layers 1" spacing="0"/>
<portSpacing port="sink_layers 2" spacing="0"/>
</process>
</operator>
<connect from_port="training set" to_op="Keras Model" to_port="training set"/>
<connect from_op="Keras Model" from_port="model" to_port="model"/>
<portSpacing port="source_training set" spacing="0"/>
<portSpacing port="sink_model" spacing="0"/>
<portSpacing port="sink_through 1" spacing="0"/>
</process>
<process expanded="true">
<operator activated="true" class="keras:apply" compatibility="1.0.003" expanded="true" height="82" name="Apply Keras Model" width="90" x="45" y="34"/>
<operator activated="true" class="performance" compatibility="8.2.000" expanded="true" height="82" name="Performance" width="90" x="179" y="34"/>
<connect from_port="model" to_op="Apply Keras Model" to_port="model"/>
<connect from_port="test set" to_op="Apply Keras Model" to_port="unlabelled data"/>
<connect from_op="Apply Keras Model" from_port="labelled data" to_op="Performance" to_port="labelled data"/>
<connect from_op="Performance" from_port="performance" to_port="performance 1"/>
<portSpacing port="source_model" spacing="0"/>
<portSpacing port="source_test set" spacing="0"/>
<portSpacing port="source_through 1" spacing="0"/>
<portSpacing port="sink_test set results" spacing="0"/>
<portSpacing port="sink_performance 1" spacing="0"/>
<portSpacing port="sink_performance 2" spacing="0"/>
</process>
</operator>
<connect from_op="Retrieve_2_Clip_ORG_CB_T2" from_port="output" to_op="Cross Validation" to_port="example set"/>
<connect from_op="Cross Validation" from_port="performance 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
Varun
https://www.varunmandalapu.com/
Be Safe. Follow precautions and Maintain Social Distancing