鱼C论坛

 找回密码
 立即注册
查看: 1770|回复: 3

神经网络问题求助!!

[复制链接]
发表于 2020-9-1 16:23:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
各位大佬们,我想问一下,我自己写了个VGG16的网络,然后把处理好的图像经过它,可是为什么会报这个错误呢??望各位大佬指教
错误类型:'tuple' object has no attribute 'ndims'
  1. import tensorflow as tf
  2. import cv2
  3. import numpy as np
  4. img_address = 'C:\\Users\\Administrator\\Desktop\\faster-rcnn-keras-master\\img\\street.jpg'

  5. def VGG(inputs):
  6.     x = inputs
  7.     # Conv1
  8.     x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
  9.     x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
  10.     x - tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
  11.     # Conv2
  12.     x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
  13.     x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
  14.     x = tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
  15.     # Conv3
  16.     x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  17.     x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  18.     x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  19.     x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
  20.     # Conv4
  21.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  22.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  23.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  24.     x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
  25.     # Conv5
  26.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  27.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  28.     x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
  29.     x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
  30.     return x


  31. def img_solve():
  32.     img = cv2.imread(img_address)
  33.     img_shape = img.shape[0:2]
  34.     img_shape_short = np.min(img_shape)
  35.     ratio_img = 600. / img_shape_short
  36.     img_collected = cv2.resize(img, (int(img_shape[0] * ratio_img), int(img_shape[1] * ratio_img)))
  37.     img_collected = np.expand_dims(img_collected.astype(np.float32) / 255.0, axis=-1)
  38.     return img_collected

  39. img = img_solve()
  40. a= VGG(img)

  41. print(img.shape)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-9-1 16:23:43 | 显示全部楼层
顶顶顶 求求了 救救孩子
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-1 16:25:08 | 显示全部楼层
这是错误类型
  1. Traceback (most recent call last):
  2.   File "C:/Users/Administrator/AppData/Roaming/JetBrains/PyCharm2020.1/scratches/scratch_2.py", line 44, in <module>
  3.     a= VGG(img)
  4.   File "C:/Users/Administrator/AppData/Roaming/JetBrains/PyCharm2020.1/scratches/scratch_2.py", line 9, in VGG
  5.     x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation='relu')(x)
  6.   File "C:\ProgramData\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 538, in __call__
  7.     self._maybe_build(inputs)
  8.   File "C:\ProgramData\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1591, in _maybe_build
  9.     self.input_spec, inputs, self.name)
  10.   File "C:\ProgramData\Anaconda3\envs\untitled\lib\site-packages\tensorflow\python\keras\engine\input_spec.py", line 109, in assert_input_compatibility
  11.     if x.shape.ndims is None:
  12. AttributeError: 'tuple' object has no attribute 'ndims'
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-1 18:28:14 | 显示全部楼层
大佬何在
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 13:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表