鱼C论坛

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

神经网络问题求助!!

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

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

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

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

def VGG(inputs):
    x = inputs
    # Conv1
    x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
    x - tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
    # Conv2
    x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3,3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.MaxPooling2D(pool_size=(2,2), strides=2)(x)
    # Conv3
    x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(256, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
    # Conv4
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
    # Conv5
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.Conv2D(512, (3, 3), padding='Same', activation=tf.nn.relu)(x)
    x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
    return x


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

img = img_solve()
a= VGG(img)

print(img.shape)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-9-1 16:23:43 | 显示全部楼层
顶顶顶 求求了 救救孩子
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

 楼主| 发表于 2020-9-1 18:28:14 | 显示全部楼层
大佬何在
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-18 20:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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