Ich schreibe eine Caffe Python-Schicht, die die Eingabe zwischen [0 255] entlang bestimmter Achse (Code angehängt) und die Weiterleitung funktioniert gut. Ist der Rückwärtsdurchlauf für eine solche Schicht erforderlich? Wenn ja, wie kann ich es umsetzen?Caffe Python-Layer-Backword-Pass-Implementierung
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
warum np.around? Wie planen Sie das zu differenzieren? – Shai
Denkst du an eine Problemumgehung für die np.around? – Mak
ignorieren Sie es vollständig? – Shai