Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Tensor' object has no attribute 'assign' #2

Closed
tsafs opened this issue Jan 22, 2019 · 4 comments
Closed

AttributeError: 'Tensor' object has no attribute 'assign' #2

tsafs opened this issue Jan 22, 2019 · 4 comments

Comments

@tsafs
Copy link

tsafs commented Jan 22, 2019

First of all, thank you for your marvellous publication and also for open-sourcing your code.

I've been trying out your code with my own datasets and came across this error when using the MCNN model:

Method:  my_archive tmp_bs16_binarySecond_offset_kmeans mcnn
C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\sklearn\preproces
sing\_encoders.py:368: FutureWarning: The handling of integer data will change i
n version 0.22. Currently, the categories are determined based on the range [0,
max(values)], while in the future they will be determined based on the unique va
lues.
If you want the future behaviour and silence this warning, you can specify "cate
gories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categor
ies to integers, then you can now use the OneHotEncoder directly.
  warnings.warn(msg, FutureWarning)
Using TensorFlow backend.
________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to

================================================================
input_1 (InputLayer)            (None, 14, 1)        0

________________________________________________________________________________
input_2 (InputLayer)            (None, 7, 1)         0

________________________________________________________________________________
input_3 (InputLayer)            (None, 5, 1)         0

________________________________________________________________________________
input_4 (InputLayer)            (None, 4, 1)         0

________________________________________________________________________________
input_5 (InputLayer)            (None, 10, 1)        0

________________________________________________________________________________
conv1d_1 (Conv1D)               (None, 14, 256)      256         input_1[0][0]

________________________________________________________________________________
conv1d_2 (Conv1D)               (None, 7, 256)       256         input_2[0][0]

________________________________________________________________________________
conv1d_3 (Conv1D)               (None, 5, 256)       256         input_3[0][0]

________________________________________________________________________________
conv1d_4 (Conv1D)               (None, 4, 256)       256         input_4[0][0]

________________________________________________________________________________
conv1d_5 (Conv1D)               (None, 10, 256)      256         input_5[0][0]

________________________________________________________________________________
max_pooling1d_1 (MaxPooling1D)  (None, 2, 256)       0           conv1d_1[0][0]

________________________________________________________________________________
max_pooling1d_2 (MaxPooling1D)  (None, 2, 256)       0           conv1d_2[0][0]

________________________________________________________________________________
max_pooling1d_3 (MaxPooling1D)  (None, 2, 256)       0           conv1d_3[0][0]

________________________________________________________________________________
max_pooling1d_4 (MaxPooling1D)  (None, 2, 256)       0           conv1d_4[0][0]

________________________________________________________________________________
max_pooling1d_5 (MaxPooling1D)  (None, 2, 256)       0           conv1d_5[0][0]

________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 2, 1280)      0           max_pooling1d_1
[0][0]
                                                                 max_pooling1d_2
[0][0]
                                                                 max_pooling1d_3
[0][0]
                                                                 max_pooling1d_4
[0][0]
                                                                 max_pooling1d_5
[0][0]
________________________________________________________________________________
conv1d_6 (Conv1D)               (None, 2, 256)       256         concatenate_1[0
][0]
________________________________________________________________________________
max_pooling1d_6 (MaxPooling1D)  (None, 2, 256)       0           conv1d_6[0][0]

________________________________________________________________________________
flatten_1 (Flatten)             (None, 512)          0           max_pooling1d_6
[0][0]
________________________________________________________________________________
dense_1 (Dense)                 (None, 256)          131328      flatten_1[0][0]

________________________________________________________________________________
dense_2 (Dense)                 (None, 2)            514         dense_1[0][0]

===============================================================
Total params: 133,378
Trainable params: 133,378
Non-trainable params: 0
________________________________________________________________________________
Traceback (most recent call last):
  File "main.py", line 112, in <module>
    fit_classifier()
  File "main.py", line 41, in fit_classifier
    classifier.fit(x_train,y_train,x_test,y_test, y_true)
  File "C:\Users\<username>\Desktop\Abschlussprojekt\Analysis\dl-4-tsc-master
\classifiers\mcnn.py", line 454, in fit
    y_test,y_true,pool_factor,filter_size)
  File "C:\Users\<username>\Desktop\Abschlussprojekt\Analysis\dl-4-tsc-master
\classifiers\mcnn.py", line 281, in train
    cost_ij, accuracy = model.train_on_batch(x,y)
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\keras\eng
ine\training.py", line 1216, in train_on_batch
    self._make_train_function()
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\keras\eng
ine\training.py", line 509, in _make_train_function
    loss=self.total_loss)
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\keras\leg
acy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\keras\opt
imizers.py", line 505, in get_updates
    self.updates.append(K.update(m, m_t))
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\keras\bac
kend\tensorflow_backend.py", line 973, in update
    return tf.assign(x, new_x)
  File "C:\Users\<username>\Anaconda3\envs\tf_gpu\lib\site-packages\tensorflo
w\python\ops\state_ops.py", line 222, in assign
    return ref.assign(value, name=name)
AttributeError: 'Tensor' object has no attribute 'assign'

I am not sure what exactly is causing this error. I have tried the MCNN model with the UCR/Adiac dataset and it worked fine. I can only imagine it being due to the different input dataset. I have used the same input dataset for other models of your study and it worked fine on them as well.

It would be much appreciated if you could lead me in the right direction. If you need any more information, please let me know.

Best regards,

@hfawaz
Copy link
Owner

hfawaz commented Jan 22, 2019

Hello,

I am very glad that my code and paper were helpful !!

As for your error regarding MCNN, I think the network is being fed a kernel_size equal to zero.

Can you make sure what values you are choosing for the kernel_size ?

kernel_size = int(ori_len * filter_size)

You should make sure that this equation is not zero.

In your case ori_len=14 (if I am not wrong).

Then you should change the values in filter_sizes.

To sum up, try to remove the 0.05 in this line.

Let me know if this fixes the error.

Best regards,

@tsafs
Copy link
Author

tsafs commented Jan 23, 2019

Thank you very much for your quick response. Indeed, your proposed solution fixed the error.

Best regards,

@hfawaz
Copy link
Owner

hfawaz commented Jan 23, 2019

Glad to help!

Do not hesitate if you have any other questions.

Best regards,

Hassan

@hfawaz hfawaz closed this as completed Jan 23, 2019
@jayanti-prasad
Copy link

where is the answer ?
This is strange that 'tf' has an object 'assign' but that does not seem working !

import tensorflow.compat.v1 as tf
tf.disable_eager_execution()
theta=tf.constant(1)
gradiants=tf.constant(3)
learning_rate=tf.constant(2)
dir(tf.assign)
['annotations', 'call', 'class', 'closure', 'code', 'defaults', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format', 'ge', 'get', 'getattribute', 'globals', 'gt', 'hash', 'init', 'init_subclass', 'kwdefaults', 'le', 'lt', 'module', 'name', 'ne', 'new', 'qualname', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', '_tf_api_names', '_tf_api_names_v1']
training_op = tf.assign(theta, theta - learning_rate * gradiants)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/ops/state_ops.py", line 228, in assign
return ref.assign(value, name=name)
AttributeError: 'Tensor' object has no attribute 'assign'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants