【发布时间】:2018-08-18 09:50:15
【问题描述】:
我正在尝试从针对汽车分类进行微调的 GoogleNet caffe 模型的最后一层提取特征。这是deploy.prototxt。我尝试了几件事:
我从 'loss3_classifier_model' 层获取了不正确的特征。
现在我正在从模型中的 'pool5' 层提取特征,如 prototxt 中给出的那样。
我不确定它是否正确,因为我为不同汽车提取的特征似乎没有太大区别。换句话说,我无法使用最后一层特征来区分汽车,我在特征上使用了欧几里得距离(正确吗?)。我没有使用softmax,因为我不想对它们进行分类,我只想要特征并使用欧几里得距离重新检查它们。
这些是我遵循的步骤:
## load the model
net = caffe.Net('deploy.prototxt',
caffe.TEST,
weights ='googlenet_finetune_web_car_iter_10000.caffemodel')
# resize the input size as I have only one image in my batch.
net.blobs["data"].reshape(1, 3, 224, 224)
# I read my image of size (x,y,3)
frame = cv2.imread(frame_path)
bbox = frame[int(x1):int(x2), int(y1):int(y2)] # getting the car, # I have stored x1,x2,x3,x4 seperatly.
# resized my image to 224,224,3, network input size.
bbox = cv2.resize(bbox, (224, 224))
# to align my input to the input of the model
bbox_input = bbox.swapaxes(1,2).reshape(3,224,224)
# fed input image to the model.
net.blobs['data'].data[0] = bbox_input
net.forward()
# features from pool5 layer or the last layer.
temp = net.blobs["pool5"].data[0]
现在,我想确认这些步骤是否正确?我是 caffe 的新手,我不确定我上面写的步骤。
【问题讨论】:
标签: python deep-learning caffe pycaffe