我目前正在复制这段代码
在转换文件中,我遇到了一个问题。
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)
我有这个错误
attributeerror:在用户代码中:
b:\stage\skeleton2\transform\u 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 Package 器**返回目标(*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返回x.shape.rank
attributeerror:“tensorvariable”对象没有属性“rank”
这是我的进口货
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
我找不到任何解决方案(我对x.shape[0]也有一个“无”的问题,但我认为这些错误没有联系)
谢谢
编辑:如果我只使用keras而不是tensoflow.keras,我有这个错误
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'
我已经测试了keras 2.4和2.2
暂无答案!
目前还没有任何答案,快来回答吧!