我正在寫一個caffe python圖層,它沿着特定軸(附加代碼)轉售[0 255]之間的輸入,並且正向傳遞正常工作。這個圖層是否需要向後傳遞?如果是這樣,我該如何執行它?Caffe python圖層底部字符傳遞實現
caffe_root = 'caffe_root'
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
import numpy as np
class scale_layer(caffe.Layer):
def setup(self, bottom, top):
assert len(bottom)==1 and len(top)==1, "scale_layer expects a single input and a single output"
def reshape(self, bottom, top):
top[0].reshape(*bottom[0].data.shape)
def forward(self, bottom, top):
in_ = np.array(bottom[0].data)
x_min = in_.min(axis=(0, 1), keepdims=True)
x_max = in_.max(axis=(0, 1), keepdims=True)
top[0].data[...] = np.around(255*((in_-x_min)/(x_max-x_min)))
def backward(self, top, propagate_down, bottom):
# backward pass is not implemented!
???????????????????????????
pass
爲什麼np.around?你如何計劃區分這一點? – Shai
您是否想過使用任何解決方法來執行np.around? – Mak
完全忽略它? – Shai