我正在尝试获取相对于输入图像的损失渐变。在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
,我该怎么办?