add working version
Browse filesFiles changed (5)
17 unmodified lines18192021222324252616 unmodified lines4344454647484950113 unmodified lines16416516616716816917017117217317417517617717817918018118218318418518618715 unmodified lines20320420520620717 unmodified linesimport csvimport jsonimport osimport datasetsfrom datasets.tasks import ImageClassification_CITATION = """\@article{FeiFei2004LearningGV,16 unmodified lines_LICENSE = "CC BY 4.0"_DATA_URL = "brand_new_data/caltech-101.zip"# _DATA_URL = "brand_new_data/caltech-101/101_ObjectCategories.tar.gz"_NAMES = ["accordion",113 unmodified linesdescription=_DESCRIPTION,features=datasets.Features({"img": datasets.Image(),"label": datasets.features.ClassLabel(names=_NAMES),}),supervised_keys=("img", "label"),homepage=_HOMEPAGE,license=_LICENSE,citation=_CITATION,task_templates=ImageClassification(image_column="img", label_column="label"),)def _split_generators(self, dl_manager):# ----- Work in progress here -----data_dir = dl_manager.download_and_extract(_DATA_URL)files = dl_manager.iter_files(data_dir)# ---------------------------------return [datasets.SplitGenerator(name=datasets.Split.TRAIN,15 unmodified lines# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`def _generate_examples(self, filepath, split):# TODOpass17 unmodified lines181920212223242526272816 unmodified lines4546474849505152113 unmodified lines16616716816917017117217317417517617717817918018118218318418518615 unmodified lines20220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223317 unmodified linesimport csvimport jsonimport osfrom pathlib import Pathimport datasetsfrom datasets.tasks import ImageClassificationimport numpy as np_CITATION = """\@article{FeiFei2004LearningGV,16 unmodified lines_LICENSE = "CC BY 4.0"# _DATA_URL = "brand_new_data/caltech-101.zip"_DATA_URL = "brand_new_data/caltech-101/101_ObjectCategories.tar.gz"_NAMES = ["accordion",113 unmodified linesdescription=_DESCRIPTION,features=datasets.Features({"image": datasets.Image(),"label": datasets.features.ClassLabel(names=_NAMES),}),supervised_keys=("image", "label"),homepage=_HOMEPAGE,license=_LICENSE,citation=_CITATION,task_templates=ImageClassification(image_column="image", label_column="label"),)def _split_generators(self, dl_manager):data_dir = dl_manager.download_and_extract(_DATA_URL)return [datasets.SplitGenerator(name=datasets.Split.TRAIN,15 unmodified lines# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`def _generate_examples(self, filepath, split):# Same stratagy as the one proposed in TF datasetsis_train_split = (split == "train")data_dir = Path(filepath) / "101_ObjectCategories"# Sets random seed so the random partitioning of files is the same when# called for the train and test splits.numpy_original_state = np.random.get_state()np.random.seed(1234)for class_dir in data_dir.iterdir():fnames = [image_path for image_path in class_dir.iterdir() if image_path.name.endswith(".jpg")]assert [image_path for image_path in class_dir.iterdir() if not image_path.name.endswith(".jpg")] == []# _TRAIN_POINTS_PER_CLASS datapoints are sampled for the train split,# the others constitute the test split.if _TRAIN_POINTS_PER_CLASS > len(fnames):raise ValueError("Fewer than {} ({}) points in class {}".format(_TRAIN_POINTS_PER_CLASS, len(fnames), class_dir.name))train_fnames = np.random.choice(fnames, _TRAIN_POINTS_PER_CLASS, replace=False)test_fnames = set(fnames).difference(train_fnames)fnames_to_emit = train_fnames if is_train_split else test_fnamesfor image_file in fnames_to_emit:record = {"image": str(image_file),"label": class_dir.name.lower(),}yield "%s/%s" % (class_dir.name.lower(), image_file), record# Resets the seeds to their previous states.np.random.set_state(numpy_original_state)
123version https://git-lfs.github.com/spec/v1oid sha256:af6ece2f339791ca20f855943d8b55dd60892c0a25105fcd631ee3d6430f9926size 131740031123version https://git-lfs.github.com/spec/v1oid sha256:1717f4e10aa837b05956e3f4c94456527b143eec0d95e935028b30aff40663d8size 140288001234567891011121314151617181920212223242526272829303132333435363738394041424344function show_annotation(imgfile, annotation_file);
%%
%% imgfile: string
%% annotation_file: string
%%
%% written by by Fei-Fei Li - November 2004
%%
IMTYPE = 'jpg';
GUIDELINE_MODE = 1;
%% Parameters
%label_abbrev = {'LE', 'RE', 'LN', 'NB', 'RN', 'LM', 'RM'};
LARGEFONT = 28;
MEDFONT = 18;
BIG_WINDOW = get(0,'ScreenSize');
SMALL_WINDOW = [100 100 512 480];
%% load the annotated data
load(annotation_file, 'box_coord', 'obj_contour');
%% Read and display image
ima = imread(imgfile);
ff=figure(1); clf; imagesc(ima); axis image; axis ij; hold on;
% black and white images
if length(size(ima))<3
colormap(gray);
end
set(ff,'Position',SMALL_WINDOW);
%% show box
box_handle = rectangle('position', [box_coord(3), box_coord(1), box_coord(4)-box_coord(3), box_coord(2)-box_coord(1)]);
set(box_handle, 'edgecolor','y', 'linewidth',5);
%% show contour
for cc = 1:size(obj_contour,2)
if cc < size(obj_contour,2)
plot([obj_contour(1,cc), obj_contour(1,cc+1)]+box_coord(3), [obj_contour(2,cc), obj_contour(2,cc+1)]+box_coord(1), 'r','linewidth',4);
else
plot([obj_contour(1,cc), obj_contour(1,1)]+box_coord(3), [obj_contour(2,cc), obj_contour(2,1)]+box_coord(1), 'r','linewidth',4);
end
end
title(imgfile);
Caltech-101.py+36-10
brand_new_data/caltech-101/101_ObjectCategories.tar.gzAdded+3
brand_new_data/caltech-101/101_ObjectCategories.tar.gz.lockAdded
brand_new_data/caltech-101/Annotations.tarAdded+3
brand_new_data/caltech-101/show_annotation.mAdded+44