神经网络问题求助!!
各位大佬们,我想问一下,我自己写了个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
img_shape_short = np.min(img_shape)
ratio_img = 600. / img_shape_short
img_collected = cv2.resize(img, (int(img_shape * ratio_img), int(img_shape * 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)
顶顶顶 求求了 救救孩子{:10_247:}{:10_247:}{:10_247:} 这是错误类型
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' 大佬何在{:10_269:}
页:
[1]