0

I'm currently reproducing this code

In the transform_rnn file, I have an issue.

class augmentaion(Layer):
def __init__(self,**kwargs):
    self.supports_masking = True
    self.uses_learning_phase = True
    super(augmentaion, self).__init__(**kwargs)

def compute_mask(self, input, mask):
    return mask
def call(self,x,training=None):
    deta1 = 0.3
    deta2 = 0.3
    deta3 = 0.3
    seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    theta1 = rng.uniform(size=(x.shape[0],1),low=-deta1,high=deta1,dtype='float32')
    theta2 = rng.uniform(size=(x.shape[0],1),low=-deta2,high=deta2,dtype='float32')
    theta3 = rng.uniform(size=(x.shape[0],1),low=-deta3,high=deta3,dtype='float32')
    theta = K.concatenate([theta1,theta2,theta3],axis=-1)
    theta = K.tile(theta,x.shape[1])
    theta = theta.reshape((x.shape[0], x.shape[1], 3))

    theta = theta.reshape((theta.shape[0]*theta.shape[1], theta.shape[2]))
    M = _fusion(theta)
    output = _transform_rot(M, x)

    return K.in_train_phase(output,x,training = training)

I have this error

AttributeError: in user code:

B:\Stage\skeleton2\transform_rnn.py:171 call * theta = K.concatenate([theta1,theta2,theta3],axis=-1) C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\util\dispatch.py:206 wrapper ** return target(*args, **kwargs) C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\backend.py:3087 concatenate rank = ndim(tensors[0]) C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\tensorflow\python\keras\backend.py:1482 ndim return x.shape.rank

AttributeError: 'TensorVariable' object has no attribute 'rank'

Here are my imports

import theano.tensor as T
import numpy as np
import theano
from tensorflow.keras import backend as K
from keras.engine.topology import Layer
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
floatX = theano.config.floatX

I can't find any solutions (I also have a problem with x.shape[0] which is 'NONE', but I don't think these errors are linked)

Thanks!

Edit : If I use just keras instead of tensoflow.keras, I have this error

Traceback (most recent call last):

  File "B:\Stage\skeleton2\va-rnn.py", line 38, in <module>
    from keras import initializers

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\utils\__init__.py", line 26, in <module>
    from .multi_gpu_utils import multi_gpu_model

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\utils\multi_gpu_utils.py", line 7, in <module>
    from ..layers.merge import concatenate

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\layers\__init__.py", line 4, in <module>
    from ..engine.base_layer import Layer

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\engine\__init__.py", line 3, in <module>
    from .input_layer import Input

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\engine\input_layer.py", line 7, in <module>
    from .base_layer import Layer

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\engine\base_layer.py", line 12, in <module>
    from .. import initializers

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\initializers\__init__.py", line 124, in <module>
    populate_deserializable_objects()

  File "C:\Users\Users\anaconda3\envs\myenv\lib\site-packages\keras\initializers\__init__.py", line 82, in populate_deserializable_objects
    generic_utils.populate_dict_with_module_objects(

AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

I've tested keras 2.4 and 2.2

14
  • Why are you mixing theano, keras, and tensorflow.keras imports? This heavy mix will not work, if you use theano you need to use keras with theano backend (which tf.keras does not support) Commented Jul 9, 2021 at 11:09
  • In the original code there is just "from keras import backend as K", but there is an error, so I add "tensorflow.keras". Do you think the error can come from there ? Commented Jul 9, 2021 at 11:37
  • Mixing keras and tf.keras is bad, mixing them with theano is very bad, as I said it will not work, you need to only use keras with theano backend. (not tf.keras). Also do you see the error is happening inside tensorflow.keras? Commented Jul 9, 2021 at 11:40
  • If I use just keras for the backend I have this error "AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'", and with tf.keras I don't have this error Commented Jul 9, 2021 at 11:46
  • You are using a version of Keras that does not have the theano backend, you need to use latest Keras 2.2.x or 2.3.x, and please stop mentioning tf.keras as it is irrelevant here. Commented Jul 9, 2021 at 11:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.