for k in args: TouchFile(pjoin(dir, k)) for k, v in kwargs.items(): path = pjoin(dir, k) os.mkdir(path) if isinstance(v, dict): MakeDirs(path, **v) else: MakeDirs(path, *v) def MockDirs(*args, **kwargs): temp_dir = TempDir() MakeDirs(temp_dir.dir, *args, **kwargs) return temp_dir EXAMPLE_CORPUS = glab.GetExampleCorpus() EXAMPLE_LARGE_CORPUS = glab.GetLargeExampleCorpus() def ImageDict(num_classes, start = 1, end = 5): return dict(('cls%d' % c, [ 'cls%d_img%d.jpg' % (c, i) for i in range(start, end) ]) for c in range(1, num_classes + 1)) CLASSES2 = ('cls1', 'cls2') TRAIN_IMAGES2 = ImageDict(2, end = 3) TEST_IMAGES2 = ImageDict(2, start = 3, end = 5) IMAGES2 = ImageDict(2, end = 5) CLASSES3 = ('cls1', 'cls2', 'cls3') TRAIN_IMAGES3 = ImageDict(3, end = 3) TEST_IMAGES3 = ImageDict(3, start = 3, end = 5)
import os import unittest from glimpse import glab from glimpse.models.misc import LayerSpec, InputSource, \ InputSourceLoadException, BaseLayer, BaseState, BaseModel, \ DependencyError, ImprintS2Prototypes EXAMPLE_IMAGE = os.path.join(glab.GetExampleCorpus(), 'cats', 'Marcus_bed.jpg') EXAMPLE_IMAGE2 = os.path.join(glab.GetExampleCorpus(), 'dogs', '41-27Monate1.JPG') EXAMPLE_IMAGE_BAD = '/invalid-file-name.jpg' class Layer(BaseLayer): RESHAPED_IMAGE = LayerSpec("r", "reshape-image", BaseLayer.IMAGE) class Model(BaseModel): LayerClass = Layer ParamClass = object StateClass = BaseState def _BuildSingleNode(self, output_id, state): if output_id == Layer.RESHAPED_IMAGE.id: data = state[Layer.IMAGE.id] return data.reshape((1, ) + data.shape)