Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';KerasTensor&x27;对象没有属性'_凯拉斯#u形';_Python_Tensorflow_Image Processing_Keras_Resnet - Fatal编程技术网

Python 属性错误:';KerasTensor&x27;对象没有属性'_凯拉斯#u形';

Python 属性错误:';KerasTensor&x27;对象没有属性'_凯拉斯#u形';,python,tensorflow,image-processing,keras,resnet,Python,Tensorflow,Image Processing,Keras,Resnet,嗨,我正在制作一个用于训练数据集的模型,但在我的resnet_模型中,我遇到了属性错误,所以请帮助我解决这个错误。代码是否如下所示: from Lib.data_loader import DataLoader from Lib.resnet_model import Resnet3DBuilder from Lib.HistoryGraph import HistoryGraph import Lib.image as img from Lib.utils import mkdirs #imp

嗨,我正在制作一个用于训练数据集的模型,但在我的resnet_模型中,我遇到了属性错误,所以请帮助我解决这个错误。代码是否如下所示:

from Lib.data_loader import DataLoader
from Lib.resnet_model import Resnet3DBuilder
from Lib.HistoryGraph import HistoryGraph
import Lib.image as img
from Lib.utils import mkdirs
#import tensorflow as tf
import os

from math import ceil

from keras.optimizers import SGD

#from tensorflow.keras.optimizers import SGD

from keras.callbacks import ModelCheckpoint

#from tensorflow.keras.callbacks import ModelCheckpoint

target_size = (64,96)
nb_frames = 16  # here this will get number of pictres from datasets folder
skip = 1 # using resnet we skip different layers
nb_classes = 27
batch_size = 64 
input_shape = (nb_frames,) + target_size + (3,)

workers = 8 
use_multiprocessing = False 
max_queue_size = 20 



resnet_model = Resnet3DBuilder.build_resnet_101(input_shape, nb_classes, drop_rate = 0.5)

optimizer = SGD(lr=0.01, momentum=0.9, decay=0.0001, nesterov=False)

resnet_model.compile(optimizer = optimizer, loss= "categorical_crossentropy" , metrics=["accuracy"])

model_file = os.path.join(path_model, 'resnetmodel.hdf5')

model_checkpointer = ModelCheckpoint(model_file, monitor='val_acc',verbose=1, save_best_only=True, mode='max')

history_graph = HistoryGraph(model_path_name = os.path.join(path_model, "graphs"))

nb_sample_train = data.train_df["video_id"].size
nb_sample_val = data.val_df["video_id"].size
所有上层代码都工作正常。 错误在这里:

AttributeError                            Traceback (most recent call last)
<ipython-input-11-be30533fbfba> in <module>
----> 1 resnet_model = Resnet3DBuilder.build_resnet_101(input_shape, nb_classes, drop_rate = 0.5)
      2 
      3 optimizer = SGD(lr=0.01, momentum=0.9, decay=0.0001, nesterov=False)
      4 
      5 resnet_model.compile(optimizer = optimizer, loss= "categorical_crossentropy" , metrics=["accuracy"])

D:\HandGesturesProject\Lib\resnet_model.py in build_resnet_101(input_shape, num_outputs, reg_factor, drop_rate)
    258     def build_resnet_101(input_shape, num_outputs, reg_factor=1e-4, drop_rate=0):
    259         """Build resnet 101."""
--> 260         return Resnet3DBuilder.build(input_shape, num_outputs, bottleneck,
    261                                      [3, 4, 23, 3], reg_factor=reg_factor, drop_rate=drop_rate)

D:\HandGesturesProject\Lib\resnet_model.py in build(input_shape, num_outputs, block_fn, repetitions, reg_factor, drop_rate)
    223         filters = 64
    224         for i, r in enumerate(repetitions):
--> 225             block = _residual_block3d(block_fn, filters=filters,
    226                                       kernel_regularizer=l2(reg_factor),
    227                                       repetitions=r, is_first_layer=(i == 0)

D:\HandGesturesProject\Lib\resnet_model.py in f(input)
    105             if i == 0 and not is_first_layer:
    106                 strides = (2, 2, 2)
--> 107             input = block_function(filters=filters, strides=strides,
    108                                    kernel_regularizer=kernel_regularizer,
    109                                    is_first_block_of_first_layer=(

D:\HandGesturesProject\Lib\resnet_model.py in f(input)
    164                                    )(conv_3_3)
    165 
--> 166         return _shortcut3d(input, residual)
    167 
    168     return f

D:\HandGesturesProject\Lib\resnet_model.py in _shortcut3d(input, residual)
     76 
     77 def _shortcut3d(input, residual):
---> 78     stride_dim1 = input._keras_shape[DIM1_AXIS] \
     79         // residual._keras_shape[DIM1_AXIS]
     80     stride_dim2 = input._keras_shape[DIM2_AXIS] \
AttributeError回溯(最近一次调用)
在里面
---->1 resnet_model=Resnet3DBuilder.build_resnet_101(输入_形状,nb_类,下降率=0.5)
2.
3优化器=SGD(lr=0.01,动量=0.9,衰减=0.0001,nesterov=False)
4.
5 resnet_model.compile(优化器=优化器,loss=“categorical_crossentropy”,metrics=[“accurity”])
D:\HandGesturesProject\Lib\resnet\u model.py in build\u resnet\u 101(输入形状、数量输出、注册系数、下降率)
258 def build_resnet_101(输入形状,数量输出,注册系数=1e-4,下降率=0):
259“生成resnet 101”
-->260返回Resnet3DBuilder.build(输入形状、输出数量、瓶颈、,
261[3,4,23,3],注册系数=注册系数,下降率=下降率)
D:\HandGesturesProject\Lib\resnet\u model.py内建(输入形状、数量输出、块fn、重复、注册因子、下降率)
223个过滤器=64个
224对于枚举中的i,r(重复):
-->225块=剩余块3D(块fn,过滤器=过滤器,
226核正则化器=l2(正则因子),
227重复次数=r,为第一层(i==0)
D:\HandGesturesProject\Lib\resnet\u model.py(输入)
105如果i==0且不是第一层:
106步=(2,2,2)
-->107输入=块_功能(过滤器=过滤器,步幅=步幅,
108核正则化器=核正则化器,
109是第一层的第一块=(
D:\HandGesturesProject\Lib\resnet\u model.py(输入)
164)(会议3)
165
-->166返回\u shortcut3d(输入,剩余)
167
168返回f
D:\HandGesturesProject\Lib\resnet\u model.py in\u shortcut3d(输入,剩余)
76
77 def_shortcut3d(输入,剩余):
--->78步幅_dim1=输入。_凯拉斯_形状[dim1_轴]\
79//残余。_keras_形状[DIM1_轴]
80步长尺寸2=输入。_keras_形状[dim2_轴]\
AttributeError:“KerasTensor”对象没有属性“\u keras\u shape”


因此,请帮助我解决此错误,即使我正在升级其库,我也无法理解它。

属性
\u keras\u形状
在tensor flow>2.0中不存在。请升级库,使其与>2.0兼容,或者设置虚拟环境以支持它

要测试的小程序

import tensorflow as tf
from keras.layers import Input

s = Input(shape=[1], dtype=tf.float32, name='1')
print("shape of s is: ",s._keras_shape) # (None, 1)
tf.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

如果您还没有准备好使用2.0,解决方法是什么

创建虚拟环境:tensor1

virtualenv -p 2.7 tensor1
在tensor和keras上安装旧版本

pip install tensorflow==1.15
pip install keras==2.2.4 

然后希望这个错误会消失,但是你可能会得到新的错误。

我可以从Lib
了解更多关于这个
的信息吗,这是你的本地包吗?因为我觉得你在tensorflow>2上,而Lib是建立在以前的版本上的。是的Lib是我的本地包folderi我正在使用虚拟环境谢谢所有帮助我的人我!实际上我的错误是因为在我使用Keras 2.4.x和tensorflow 2.4.2之前版本的不同,然后我卸载这些版本,使用tensorflow==2.2.0的Keras==2.3.1,我的问题就解决了。当我安装tensorflow 1.15时,出现以下错误:错误:找不到满足要求的版本水泥张量流量==1.15(来自版本:2.2.0rc1、2.2.0rc2、2.2.0rc3、2.2.0rc4、2.2.0、2.2.1、2.2.2.2、2.3.0rc0、2.3.0rc1、2.3.0、2.3.0、2.3.1、2.4.0rc0、2.4.0rc1、2.4.0rc2.0、2.4.0rc4.0rc4.0rc4、2.0、2.4.0、2.0、2.5.0、2.5、2.0、2.5、RC2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0、2.0错误:找不到tensorflow==1.15的匹配发行版,谢谢所有帮助我的人!事实上,在我使用Keras 2.4.x和tensorflow 2.4.2之前,我的错误是因为版本不同,然后我卸载了这些版本,并使用tensorflow==2.2.0的Keras==2.3.1解决了我的问题。