이 작업에는 Conv2D
기능을 사용할 수 있습니다. 참조 here을 참조하고 예제 튜토리얼 here을 읽을 수도 있습니다. 이 솔루션에 대한 참고 사항 : 커널이 대칭
- 때문에, 당신은 무시할 수
filter_flip
매개 변수 당신이 처음
- Conv2D 합 모든 채널을 바꿀 필요가 있으므로 Conv2D는, 4D 입력 매개 변수로 커널 형태를 사용
- (? 난 당신의 경우에 생각이 채널이라고 변수가 RGB에게 적합한 'K') 그래서 당신은
이, 내가 여기에 간단한 커널 내 예제 코드를 사용한다 먼저 분리해야합니다
을
import numpy as np
import theano
import theano.tensor as T
from theano.tensor.nnet import conv2d
# original image
img = [[[1, 2, 3, 4], #R channel
[1, 1, 1, 1], #
[2, 2, 2, 2]], #
[[1, 1, 1, 1], #G channel
[2, 2, 2, 2], #
[1, 2, 3, 4]], #
[[1, 1, 1, 1], #B channel
[1, 2, 3, 4], #
[2, 2, 2, 2],]]#
# separate and reshape each channel to 4D
R = np.asarray([[img[0]]], dtype='float32')
G = np.asarray([[img[1]]], dtype='float32')
B = np.asarray([[img[2]]], dtype='float32')
# 4D kernel from the original : [1,0,1]
kernel = np.asarray([[[[1],[0],[1]]]], dtype='float32')
# theano convolution
t_img = T.ftensor4("t_img")
t_kernel = T.ftensor4("t_kernel")
result = conv2d(
input = t_img,
filters=t_kernel,
filter_shape=(1,1,1,3),
border_mode = 'half')
f = theano.function([t_img,t_kernel],result)
# compute each channel
R = f(R,kernel)
G = f(G,kernel)
B = f(B,kernel)
# reshape again
img = np.asarray([R,G,B])
img = np.reshape(img,(3,3,4))
print img
코드에 대해 논의 할 사항이 있으면 의견을 말하십시오. 희망이 도움이됩니다.
안녕하세요, 위의 코드를 실행했는데 다음과 같은 오류가 나타납니다 - 'ValueError : 새 배열의 전체 크기는 변경되지 않아야합니다.' – Anonynags
또 다른 오류는 회선 함수의 '절반'모드가 구현되지 않았다는 것입니다. 예외 : Mode half not implemented' - Numpy와 Scipy가 최신 업데이트로 설치되었지만 오류가 계속 발생합니다. – Anonynags
두 번째 오류로 인해 업데이트 버전 0.8을 사용하려고합니다. 첫 번째 오류를 확인합니다. – malioboro