MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / ImageNet

Class ImageNet

python/graphvite/dataset.py:864–1069  ·  view source on GitHub ↗

ImageNet dataset for visualization. Splits: train_image, train_feature_data, train_label, train_hierarchical_label, valid_image, valid_feature_data, valid_label, valid_hierarchical_label

Source from the content-addressed store, hash-verified

862
863
864class ImageNet(Dataset):
865 """
866 ImageNet dataset for visualization.
867
868 Splits:
869 train_image, train_feature_data, train_label, train_hierarchical_label,
870 valid_image, valid_feature_data, valid_label, valid_hierarchical_label
871 """
872
873 def __init__(self):
874 super(ImageNet, self).__init__(
875 "imagenet",
876 urls={
877 "train_image": "http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_train.tar",
878 "train_feature_data": [], # depends on `train_image`
879 "train_label": [], # depends on `train_image`
880 "train_hierarchical_label": [], # depends on `train_image`
881 "valid_image": ["http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar",
882 "http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz"],
883 "valid_feature_data": [], # depends on `valid_image`
884 "valid_label": "http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz",
885 "valid_hierarchical_label":
886 "http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz",
887 "feature_data": [], # depends on `train_feature_data` & `valid_feature_data`
888 "label": [], # depends on `train_label` & `valid_label`
889 "hierarchical_label": [], # depends on `train_hierarchical_label` & `valid_hierarchical_label`
890 }
891 )
892
893 def import_wordnet(self):
894 import nltk
895 try:
896 nltk.data.find("corpora/wordnet")
897 except LookupError:
898 nltk.download("wordnet")
899 from nltk.corpus import wordnet
900 try:
901 wordnet.synset_from_pos_and_offset
902 except AttributeError:
903 wordnet.synset_from_pos_and_offset = wordnet._synset_from_pos_and_offset
904 return wordnet
905
906 def get_name(self, synset):
907 name = synset.name()
908 return name[:name.find(".")]
909
910 def readable_label(self, labels, save_file, hierarchy=False):
911 wordnet = self.import_wordnet()
912
913 if hierarchy:
914 logger.info("generating human-readable hierarchical labels")
915 else:
916 logger.info("generating human-readable labels")
917 synsets = []
918 for label in labels:
919 pos = label[0]
920 offset = int(label[1:])
921 synset = wordnet.synset_from_pos_and_offset(pos, offset)

Callers 1

dataset.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected