Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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 如何使用VGG-16和Imagenet模型(重量)训练数据_Python_Python 3.x_Image Processing_Keras_Imagenet - Fatal编程技术网

Python 如何使用VGG-16和Imagenet模型(重量)训练数据

Python 如何使用VGG-16和Imagenet模型(重量)训练数据,python,python-3.x,image-processing,keras,imagenet,Python,Python 3.x,Image Processing,Keras,Imagenet,我正在试用GitHub的一些代码。这个程序是关于情绪识别的,我正在尝试创建瓶颈特征来使用VGG-16-Imagenet模型训练数据。我试图使用图像网,但出现了错误 from keras.applications.vgg16 import VGG16 #creating bottleneck features for train data using VGG-16- Image-net model model = VGG16(weights='imagenet', include_top=Fals

我正在试用GitHub的一些代码。这个程序是关于情绪识别的,我正在尝试创建瓶颈特征来使用VGG-16-Imagenet模型训练数据。我试图使用图像网,但出现了错误

from keras.applications.vgg16 import VGG16
#creating bottleneck features for train data using VGG-16- Image-net model
model = VGG16(weights='imagenet', include_top=False)
SAVEDIR = "../Desktop/Dataset_All_Human/Bottleneck_Features/Bottleneck_CombinedTrain/"
SAVEDIR_LABELS = "../Desktop/Dataset_All_Human/Bottleneck_Features/CombinedTrain_Labels/"
batch_size = 10
for i in range(int(len(Train_Combined)/batch_size)):
    x, y = loadCombinedTrainBatch(batch_size)
    print("Batch {} loaded".format(i+1))
    
    np.save(os.path.join(SAVEDIR_LABELS, "bottleneck_labels_{}".format(i+1)), y)
    
    print("Creating bottleneck features for batch {}". format(i+1))
    bottleneck_features = model.predict(x)
    np.save(os.path.join(SAVEDIR, "bottleneck_{}".format(i+1)), bottleneck_features)
    print("Bottleneck features for batch {} created and saved\n".format(i+1))
结果和错误消息

Using TensorFlow backend.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-3b2c5a440d9d> in <module>
      1 from keras.applications.vgg16 import VGG16
      2 #creating bottleneck features for train data using VGG-16- Image-net model
----> 3 model = VGG16(weights='imagenet', include_top=False)
      4 SAVEDIR = "../Desktop/Dataset_All_Human/Bottleneck_Features/Bottleneck_CombinedTrain/"
      5 SAVEDIR_LABELS = "../Desktop/Dataset_All_Human/Bottleneck_Features/CombinedTrain_Labels/"

~\Anaconda3\lib\site-packages\keras\applications\__init__.py in wrapper(*args, **kwargs)
     18         kwargs['models'] = models
     19         kwargs['utils'] = utils
---> 20         return base_fun(*args, **kwargs)
     21 
     22     return wrapper

~\Anaconda3\lib\site-packages\keras\applications\vgg16.py in VGG16(*args, **kwargs)
      9 @keras_modules_injection
     10 def VGG16(*args, **kwargs):
---> 11     return vgg16.VGG16(*args, **kwargs)
     12 
     13 

~\Anaconda3\lib\site-packages\keras_applications\vgg16.py in VGG16(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs)
    110                       activation='relu',
    111                       padding='same',
--> 112                       name='block1_conv1')(img_input)
    113     x = layers.Conv2D(64, (3, 3),
    114                       activation='relu',

~\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs)
     73         if _SYMBOLIC_SCOPE.value:
     74             with get_graph().as_default():
---> 75                 return func(*args, **kwargs)
     76         else:
     77             return func(*args, **kwargs)

~\Anaconda3\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs)
    444                 # Raise exceptions in case the input is not compatible
    445                 # with the input_spec specified in the layer constructor.
--> 446                 self.assert_input_compatibility(inputs)
    447 
    448                 # Collect input shapes to build layer.

~\Anaconda3\lib\site-packages\keras\engine\base_layer.py in assert_input_compatibility(self, inputs)
    308         for x in inputs:
    309             try:
--> 310                 K.is_keras_tensor(x)
    311             except ValueError:
    312                 raise ValueError('Layer ' + self.name + ' was called with '

~\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py in is_keras_tensor(x)
    693     
    694     """
--> 695     if not is_tensor(x):
    696         raise ValueError('Unexpectedly found an instance of type `' +
    697                          str(type(x)) + '. '

~\Anaconda3\lib\site-packages\keras\back-end\tensorflow_backend.py in is_tensor (x)
    701
    702 def is_tensor (x):
&ndash; > 703    return isinstance (x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like (x)
    704
    705

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
使用TensorFlow后端。
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在里面
1来自keras.applications.vgg16导入vgg16
2#使用VGG-16-图像网络模型为列车数据创建瓶颈特征
---->3型号=VGG16(权重='imagenet',包括顶部=假)
4 SAVEDIR=“../Desktop/Dataset\u所有人/瓶颈\u功能/瓶颈\u组合训练/”
5 SAVEDIR_LABELS=“../Desktop/Dataset_All_Human/瓶颈_Features/CombinedTrain_LABELS/”
包装中的~\Anaconda3\lib\site packages\keras\applications\\uuuu init\uuuuuu.py(*args,**kwargs)
18 kwargs[“模型”]=模型
19 kwargs['utils']=utils
--->20返回基地乐趣(*args,**kwargs)
21
22返回包装器
vgg16中的~\Anaconda3\lib\site packages\keras\applications\vgg16.py(*args,**kwargs)
9@keras\u模块\u注入
10 def VGG16(*args,**kwargs):
--->11返回vgg16.vgg16(*args,**kwargs)
12
13
vgg16中的~\Anaconda3\lib\site packages\keras\u applications\vgg16.py(包括顶部、权重、输入张量、输入形状、池、类、**kwargs)
110激活='relu',
111“相同”,
-->112 name='block1_conv1')(img_输入)
113 x=层。Conv2D(64,(3,3),
114激活='relu',
符号包装中的~\Anaconda3\lib\site packages\keras\backend\tensorflow\u backend.py(*args,**kwargs)
73如果符号范围值:
74带有get_graph()。作为_default():
--->75返回函数(*args,**kwargs)
76.其他:
77返回函数(*args,**kwargs)
~\Anaconda3\lib\site packages\keras\engine\base\u layer.py in\uuuuu调用(self,input,**kwargs)
444#在输入不兼容的情况下引发异常
445#具有图层构造函数中指定的输入规格。
-->446.断言输入兼容性(输入)
447
448#收集输入形状以构建图层。
~\Anaconda3\lib\site packages\keras\engine\base\u layer.py在assert\u input\u兼容性(self,inputs)中
308对于x输入:
309试试看:
-->310 K.is_keras_张量(x)
311除值错误外:
312 raise VALUERROR('Layer'+self.name+'被调用为'
is\u keras\u tensor(x)中的~\Anaconda3\lib\site packages\keras\backend\tensorflow\u backend.py
693
694     """
-->695如果不是张量(x):
696 raise VALUERROR('意外发现类型为`'的实例'+
697 str(类型(x))+'。'
is\u tensor(x)中的~\Anaconda3\lib\site packages\keras\back-end\tensorflow\u backend.py
701
702 def是_张量(x):
&ndash;>703返回是恒量(x,tf_ops._TensorLike)或tf_ops.is_density_tensor_like(x)
704
705
AttributeError:模块“tensorflow.python.framework.ops”没有属性“\u TensorLike”

变量
x
包含什么?