Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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 用CNN预测图像中的多圆半径_Python_Tensorflow_Machine Learning_Keras_Neural Network - Fatal编程技术网

Python 用CNN预测图像中的多圆半径

Python 用CNN预测图像中的多圆半径,python,tensorflow,machine-learning,keras,neural-network,Python,Tensorflow,Machine Learning,Keras,Neural Network,我试图用卷积神经网络计算图像中的圆半径。 我只有图像作为输入,输出端的半径,因此映射为[image]->[radius of circle] 输入维度和神经网络架构如下: from tensorflow.keras import layers from tensorflow.keras import Model img_input = layers.Input(shape=(imgsize, imgsize, 1)) x = layers.Conv2D(16, (3,3), activatio

我试图用卷积神经网络计算图像中的圆半径。 我只有图像作为输入,输出端的半径,因此映射为[image]->[radius of circle]

输入维度和神经网络架构如下:

from tensorflow.keras import layers
from tensorflow.keras import Model
img_input = layers.Input(shape=(imgsize, imgsize, 1))

x = layers.Conv2D(16, (3,3), activation='relu', strides =1, padding = 'same')(img_input)
x = layers.Conv2D(32, (3,3), activation='relu', strides = 2)(x)
x = layers.Conv2D(128, (3,3), activation='relu', strides = 2)(x)
x = layers.MaxPool2D(pool_size=2)(x)

x = layers.Conv2D(circle_per_box, 1, activation='linear', strides = 2)(x)

output = layers.Flatten()(x)
model_CNN = Model(img_input, output)
model_CNN.summary()

model_CNN.compile(loss='mean_squared_error',optimizer= 'adam', metrics=['mse'])



X_train, X_test, Y_train, Y_test = train_test_split(image, radii, test_size=0.2, random_state=0)
print(X_train.shape, X_test.shape, Y_train.shape, Y_test.shape)

(8000, 12, 12, 1) (2000, 12, 12, 1) (8000, 1) (2000, 1)

Y_train
array([[1.01003947],
       [1.32057104],
       [0.34507285],
       ...,
       [1.53130402],
       [0.69527609],
       [1.85973669]])
如果我为每张图像计算一个圆,我会得到一个可靠的结果:

但是,如果每张图像有更多的圆圈(请参见图片),则相同的网络会崩溃,我得到以下结果:

两个圆的Y列形状如下:

Y_train.shape
(10000, 2)

Y.train
array([[1.81214007, 0.68388911],
       [1.47920612, 1.04222943],
       [1.90827465, 1.43238623],
       ...,
       [1.40865229, 1.65726638],
       [0.52878558, 1.94234548],
       [1.57923437, 1.19544775]])
为什么神经网络会有这样的行为? 如果我像上面描述的那样分别计算图像中生成的两个圆的半径,我会再次获得良好的结果,但如果两个圆同时出现在图像中则不会


有人有什么想法/建议吗?

您的模型如何知道多圈图像中哪个半径对应哪个圆?实际上没有半径的标签,因此网络无法真正知道哪个半径对应哪个圆。我如何实现这样的标签?(因为我只有这些图像)我想你应该将其作为一个两阶段的问题来处理:首先检测圆,然后将它们与相应的半径配对。但这不是编程讨论。你所说的编程讨论到底是什么意思@这不是关于实现,而是关于其他方面(设计、方法等),这些都不是关于SO的主题;请看报纸上的便条。