Exploiting Related and Unrelated Tasks for Hierarchical Metric Learning and Image Classification