我正在使用卷积网络创建图像的区域提议层。卷积后绘制图像时,出现形状不匹配错误。
我是CNN的新手,在进一步发展方面遇到困难。
卷积层
model = Sequential()
model.add(Conv2D(filters=3, kernel_size=(3,3),activation='relu', input_shape=(720,1280,3)))
从文件夹加载图像
images =[cv2.imread(file) for file in glob.glob("C:/Users/User/RPN/images/*.jpg")]
for i in range (0,999):
images[i]=cv2.cvtColor(images[i],cv2.COLOR_RGB2BGR)
images[i]=np.expand_dims(images[i],axis=0)
t=model.predict(images[2])
print(t)
绘制特征图
p=t
q=np.squeeze(p,axis=0)
plt.imshow(q)
RPN模型,这里k是锚点数
k=9
feature_map_tile = Input(shape=(None,None,3))
convolution_3x3 = Conv2D(filters=512,kernel_size=(3, 3),padding='same',name="3x3")(feature_map_tile)
output_deltas = Conv2D(filters= 4 * k,kernel_size=(1, 1),activation="linear",kernel_initializer="uniform",name="deltas1")(convolution_3x3)
output_scores = Conv2D(filters=1 * k,kernel_size=(1, 1),activation="sigmoid",kernel_initializer="uniform",name="scores1")(convolution_3x3)
model = Model(inputs=[feature_map_tile], outputs=[output_scores, output_deltas])
model.compile(optimizer='adam', loss='mean_squared_error') #
ty=model.predict(p)
print(ty)
绘制区域提议层
p1=ty[0]
q1=np.squeeze(p1,axis=0)
arr=np.array(q1)
plt.imshow(arr[:,:,8])
错误是:
AttributeError Traceback (most recent call last)
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\core\fromnumeric.py in squeeze(a, axis)
1381 try:
-> 1382 squeeze = a.squeeze
1383 except AttributeError:
AttributeError: 'list' object has no attribute 'squeeze'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-71-eeeec140246c> in <module>
1 p=t
----> 2 q=np.squeeze(p,axis=0)
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\core\fromnumeric.py in squeeze(a, axis)
1382 squeeze = a.squeeze
1383 except AttributeError:
-> 1384 return _wrapit(a, 'squeeze')
1385 if axis is None:
1386 return squeeze()
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds)
44 except AttributeError:
45 wrap = None
---> 46 result = getattr(asarray(obj), method)(*args, **kwds)
47 if wrap:
48 if not isinstance(result, mu.ndarray):
~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
ValueError: could not broadcast input array from shape (720,1280,9) into shape (1,720,1280)