guillaume-chevalier / LSTM-Human-Activity-Recognition

Human Activity Recognition example using TensorFlow on smartphone sensors dataset and an LSTM RNN. Classifying the type of movement amongst six activity categories - Guillaume Chevalier
MIT License
3.35k stars 938 forks source link

Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32 #7

Closed zhaishengfu closed 7 years ago

zhaishengfu commented 7 years ago

thank you for sharing. when the code runs to line: hidden = tf.split(0, config.n_steps, hidden) it has error of " Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32 " i am beginner of tensorflow, so i have no idea what is the problem

zhaishengfu commented 7 years ago

i know the answer! it should be" split(hidden, config.n_steps, 0) for my tensorflow "

sitmo commented 7 years ago

To upgrade this script to use with Tensorflow v1.0 apply the following patches:

--hidden = tf.split(0, config.n_steps, hidden)
++hidden = tf.split(hidden, config.n_steps, 0)

--lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(config.n_hidden, forget_bias=1.0)
++lstm_cell = tf.contrib.rnn.BasicLSTMCell(config.n_hidden, forget_bias=1.0)

--lsmt_layers = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * 2)
++lsmt_layers = tf.contrib.rnn.MultiRNNCell([lstm_cell] * 2)

--outputs, _ = tf.nn.rnn(lsmt_layers, hidden, dtype=tf.float32)
++outputs, _ = tf.contrib.rnn.static_rnn(lsmt_layers, hidden, dtype=tf.float32)

--tf.nn.softmax_cross_entropy_with_logits(pred_Y, Y)) + l2
++tf.nn.softmax_cross_entropy_with_logits(logits = pred_Y, labels = Y)) + l2

--tf.initialize_all_variables().run()
++tf.global_variables_initializer().run()
zhaowenyi94 commented 7 years ago

Yes and in line 25 and 40 I made these modification

#line 25:
file = open(signal_type_path, 'rb')    ===>>>         file = open(signal_type_path, 'r')

#line 40:
file = open(y_path, 'rb')     ===>>>    file = open(y_path, 'r')

but did you get the same result as shown in the Readme file?

@sitmo @zhaishengfu

preksha12 commented 7 years ago

While running the code I am getting following error TypeError: Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32. I also tried to change the code but its not working

stoicdataguy commented 7 years ago

One more update.

Old: cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y)) + l2 # Softmax loss
New: cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y)) + l2 # Softmax loss

stoicdataguy commented 7 years ago

For those facing problem with migrating the code to TensorFlow v1.0, you can consider downgrading Tensorflow to v0.12.1 You can use the following command. pip install --ignore-installed --upgrade 'tensorflow==0.12.1'

preksha12 commented 7 years ago

Even after downgrading error is same. ---> 18 _X = tf.split(0, n_steps, _X) 19 # new shape: n_steps * (batch_size, n_hidden) 20 hidden = tf.split(0, config.n_steps, hidden)

/Users/bhaskar/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.pyc in split(value, num_or_size_splits, axis, num, name) 1196 Requires that num_split evenly divide value.shape[split_dim]. 1197 -> 1198 For example: 1199 1200 ```python

/Users/bhaskar/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.pyc in _split(split_dim, value, num_split, name) 3304 index starts at 0. It is an error to squeeze a dimension that is not 1. 3305 name: A name for the operation (optional). -> 3306 3307 Returns: 3308 A Tensor. Has the same type as input.

/Users/bhaskar/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.pyc in apply_op(self, op_type_name, name, **keywords) 512 if k in default_type_attr_map: 513 if k not in attrs: --> 514 attrs[k] = default_type_attr_map[k] 515 if k not in inferred_from: 516 inferred_from[k] = "Default in OpDef"

TypeError: Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32.

guillaume-chevalier commented 7 years ago

Updated to Python 3 and TensorFlow 1.0.0

srossross commented 6 years ago

I'm not sure if this is any help to anyone, but I'll leave this here anyways. I had a little trouble with the issue above and I also could not seem to install tensorflow with pip.

To get the correct prerequisites installed I used:

conda create -n tf -c conda-forge tensorflow scikit-learn notebook matplotlib
conda activate tf