Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于capsule的输出问题 #9

Open
tinymindxx opened this issue Jan 29, 2019 · 2 comments
Open

关于capsule的输出问题 #9

tinymindxx opened this issue Jan 29, 2019 · 2 comments

Comments

@tinymindxx
Copy link

你好,有个问题想请教以下:

#搭建CNN+Capsule分类模型
input_image = Input(shape=(None,None,1))
cnn = Conv2D(64, (3, 3), activation='relu')(input_image)
cnn = Conv2D(64, (3, 3), activation='relu')(cnn)
cnn = AveragePooling2D((2,2))(cnn)
cnn = Conv2D(128, (3, 3), activation='relu')(cnn)
cnn = Conv2D(128, (3, 3), activation='relu')(cnn)
cnn = Reshape((-1, 128))(cnn)
capsule = Capsule(10, 16, 3, True)(cnn)
output = Lambda(lambda x: K.sqrt(K.sum(K.square(x), 2)), output_shape=(10,))(capsule)

model = Model(inputs=input_image, outputs=output)
model.compile(loss=lambda y_true,y_pred: y_true*K.relu(0.9-y_pred)**2 + 0.25*(1-y_true)*K.relu(y_pred-0.1)**2,
              optimizer='adam',
metrics=['accuracy'])

在这个模型中,output = Lambda(lambda x: K.sqrt(K.sum(K.square(x), 2)), output_shape=(10,))(capsule) 这一行操作的输入capsule的的结构是[batch_size,num_capsule,dim_capsule]. output执行的含义是:
default

我的理解,这个操作是将capsule的每一个分量转换成可能性(概率),那么这个地方是否可以换乘求和或者求平均呢? 采用default是否有其他的含义呢?

谢谢了.

@bojone
Copy link
Owner

bojone commented Jan 31, 2019

那是你没有通读capsule整个流程和思想。 capsule就是希望向量的模长为0~1之间,代表着激活程度(概率值),所以用向量的模长(也就是K.sqrt(K.sum(K.square(x), 2)))是最自然的

@tinymindxx
Copy link
Author

明白了,十分感谢.@bojone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants