2

我试图获得相对于输入图像的损失梯度。在 Caffe(原版)中,以下代码实现了我的目标:

### Load image into net's data layer
img = caffe.io.load_image(jpg_file)
transformed_image = transformer.preprocess('data', img)
net.blobs['data'].data[...] = transformed_image    # copy image data into memory for net

...

### Form the final label vector (one hot vector)
finalLabelVector = np.zeros((1,num_classes))
finalLabelVector[0,ground_truth_label] = 1

### Do a backward pass using finalLabelVector
# must have 'force_backward: true' set in deploy prototxt
backwardpassData = net.backward(**{net.outputs[0]: finalLabelVector})

# Get the derivative with respect to the input (data layer)
delta = backwardpassData['data']

我必须如何使用 Caffe2 Python 接口来计算与delta上面相同的?

4

0 回答 0