Created by Ronghang Hu (huronghang@hotmail.com) at Department of Electronic Engineering, Tsinghua University.
- build an MHEX Graph from ImageNET synsets (DAG label hierarchy)
meta_1k = load('+imagenet/meta_1k.mat');
G_1k = build_mhex_from_synsets(meta_1k.synsets_1k);
- dump matrix M1 and M2 in [1] to files for inference
dump_mhex_mats(G_1k, 'mhex_mats_imagenet_1k.mat', true);
- load M1 and M2 in Caffe.
3.1. your mhex layers in Caffe network prototxt should look like
# MHEX Graph
# MHEX M1
layers {
name: "mhex_mat1"
# set bottom to your input scores
bottom: "fc8_1k"
top: "mhex_mat1"
type: INNER_PRODUCT
blobs_lr: 0
blobs_lr: 0
weight_decay: 0
weight_decay: 0
# set num_output to |V_L|, number of leaf nodes
inner_product_param { num_output: 1000 }
}
# MHEX Softmax
layers {
name: "mhex_softmax"
bottom: "mhex_mat1"
top: "mhex_softmax"
type: SOFTMAX
}
# MHEX M2
layers {
name: "mhex_mat2"
bottom: "mhex_softmax"
# output marginal probabilities
top: "mhex_mat2"
type: INNER_PRODUCT
blobs_lr: 0
blobs_lr: 0
weight_decay: 0
weight_decay: 0
# set num_output to |V|, number of internal + leaf nodes
inner_product_param { num_output: 1860 }
}
3.2. Use the tool load_mhex_into_caffe.py
in package pymhex
to load M1 and M2 from MATLAB file dumped in step 2 into a Caffe network. Set parameter caffe_model=''
if you want to initialize your network from scratch. Otherwise (if you want to start by fine-tuning from a pre-trained network), set it to the path to your pre-trained caffemodel file.
3.3. Train your network in Caffe by loading the network weights generated by load_mhex_into_caffe.py
.
MHEX Graph is released under the Simplified BSD License (refer to the LICENSE file for details).
[1] R. Hu, Modified Hierarchy-Exclusion Graph for Efficient Inference and Training on DAG Label Hierarchies, in Tech Report, 2015
[2] Y. Jia, E. Shelhamer, J. Donahue, S. Karayev, J. Long, R. Girshick, S. Guadarrama and T. Darrell, Caffe: Convolutional Architecture for Fast Feature Embedding, in arXiv preprint arXiv:1408.5093, 2014.