def prepare(self): url = 'http://yann.lecun.com/exdb/mnist/' train_files = {'target': 'train-images-idx3-ubyte.gz', 'label': 'train-labels-idx1-ubyte.gz'} test_files = {'target': 't10k-images-idx3-ubyte.gz', 'label': 't10k-labels-idx1-ubyte.gz'} files = train_files if self.train else test_files data_path = get_file(url + files['target']) label_path = get_file(url + files['label']) self.data = self._load_data(data_path) self.label = self._load_label(label_path)
def prepare(self): url = "http://yann.lecun.com/exdb/mnist/" train_files = { "target": "train-images-idx3-ubyte.gz", "label": "train-labels-idx1-ubyte.gz", } test_files = { "target": "t10k-images-idx3-ubyte.gz", "label": "t10k-labels-idx1-ubyte.gz" } files = train_files if self.train else test_files data_path = get_file(url + files["target"]) label_path = get_file(url + files["label"]) self.data = self._load_data(data_path) self.label = self._load_label(label_path)
def prepare(self): url = 'https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz' self.data, self.label = load_cache_npz(url, self.train) if self.data is not None: return filepath = get_file(url) if self.train: self.data = self._load_data(filepath, 'train') self.label = self._load_label(filepath, 'train') else: self.data = self._load_data(filepath, 'test') self.label = self._load_label(filepath, 'test') self.data = self.data.reshape(-1, 3, 32, 32) save_cache_npz(self.data, self.label, url, self.train)
def prepare(self): url = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz' self.data, self.label = load_cache_npz(url, self.train) if self.data is not None: return filepath = get_file(url) if self.train: self.data = np.empty((50000, 3 * 32 * 32)) self.label = np.empty((50000), dtype=np.int) for i in range(5): self.data[i * 10000:(i + 1) * 10000] = self._load_data( filepath, i + 1, 'train') self.label[i * 10000:(i + 1) * 10000] = self._load_label( filepath, i + 1, 'train') else: self.data = self._load_data(filepath, 5, 'test') self.label = self._load_label(filepath, 5, 'test') self.data = self.data.reshape(-1, 3, 32, 32) save_cache_npz(self.data, self.label, url, self.train)
def get_shakespear(): url = 'https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt' file_name = 'shakespear.txt' path = get_file(url, file_name) with open(path, 'r') as f: data = f.read() chars = list(data) char_to_id = {} id_to_char = {} for word in data: if word not in char_to_id: new_id = len(char_to_id) char_to_id[word] = new_id id_to_char[new_id] = word indices = np.array([char_to_id[c] for c in chars]) return indices, char_to_id, id_to_char
def prepare(self): url = 'https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt' file_name = 'shakespear.txt' path = get_file(url, file_name) with open(path, 'r') as f: data = f.read() chars = list(data) char_to_id = {} id_to_char = {} for word in data: if word not in char_to_id: new_id = len(char_to_id) char_to_id[word] = new_id id_to_char[new_id] = word indices = np.array([char_to_id[c] for c in chars]) self.data = indices[:-1] self.label = indices[1:] self.char_to_id = char_to_id self.id_to_char = id_to_char
def __init__(self, pretrained=False) -> None: super().__init__() self.conv1_1 = L.Conv2d(64, kernel_size=3, stride=1, pad=1) self.conv1_2 = L.Conv2d(64, kernel_size=3, stride=1, pad=1) self.conv2_1 = L.Conv2d(128, kernel_size=3, stride=1, pad=1) self.conv2_2 = L.Conv2d(128, kernel_size=3, stride=1, pad=1) self.conv3_1 = L.Conv2d(256, kernel_size=3, stride=1, pad=1) self.conv3_2 = L.Conv2d(256, kernel_size=3, stride=1, pad=1) self.conv3_3 = L.Conv2d(256, kernel_size=3, stride=1, pad=1) self.conv4_1 = L.Conv2d(512, kernel_size=3, stride=1, pad=1) self.conv4_2 = L.Conv2d(512, kernel_size=3, stride=1, pad=1) self.conv4_3 = L.Conv2d(512, kernel_size=3, stride=1, pad=1) self.conv5_1 = L.Conv2d(512, kernel_size=3, stride=1, pad=1) self.conv5_2 = L.Conv2d(512, kernel_size=3, stride=1, pad=1) self.conv5_3 = L.Conv2d(512, kernel_size=3, stride=1, pad=1)3 self.fc6 = L.Linear(4096) self.fc7 = L.Linear(4096) self.fc8 = L.Linear(1000) if pretrained: weights_path = utils.get_file(VGG16.WEIGHT_PATH) self.load_weights(weights_path)
def __init__(self, pretrained=False): super().__init__() self.conv1_1 = L.Conv2d(3, 64, 3, 1, 1) self.conv1_2 = L.Conv2d(64, 64, 3, 1, 1) self.conv2_1 = L.Conv2d(64, 128, 3, 1, 1) self.conv2_2 = L.Conv2d(128, 128, 3, 1, 1) self.conv3_1 = L.Conv2d(128, 256, 3, 1, 1) self.conv3_2 = L.Conv2d(256, 256, 3, 1, 1) self.conv3_3 = L.Conv2d(256, 256, 3, 1, 1) self.conv4_1 = L.Conv2d(256, 512, 3, 1, 1) self.conv4_2 = L.Conv2d(512, 512, 3, 1, 1) self.conv4_3 = L.Conv2d(512, 512, 3, 1, 1) self.conv5_1 = L.Conv2d(512, 512, 3, 1, 1) self.conv5_2 = L.Conv2d(512, 512, 3, 1, 1) self.conv5_3 = L.Conv2d(512, 512, 3, 1, 1) self.fc6 = L.Linear(4096) self.fc7 = L.Linear(4096) self.fc8 = L.Linear(1000) if pretrained: weights_path = utils.get_file(VGG16.WEIGHTS_PATH) self.load_weights(weights_path)
def __init__(self, n_layers=152, pretrained=False): super().__init__() if n_layers == 50: block = [3, 4, 6, 3] elif n_layers == 101: block = [3, 4, 23, 3] elif n_layers == 152: block = [3, 8, 36, 3] else: raise ValueError('The n_layers argument should be either 50, 101,' ' or 152, but {} was given.'.format(n_layers)) self.conv1 = L.Conv2d(3, 64, 7, 2, 3) self.bn1 = L.BatchNorm() self.res2 = BuildingBlock(block[0], 64, 64, 256, 1) self.res3 = BuildingBlock(block[1], 256, 128, 512, 2) self.res4 = BuildingBlock(block[2], 512, 256, 1024, 2) self.res5 = BuildingBlock(block[3], 1024, 512, 2048, 2) self.fc6 = L.Linear(1000) if pretrained: weights_path = utils.get_file(ResNet.WEIGHTS_PATH.format(n_layers)) self.load_weights(weights_path)
def labels(): url = 'https://gist.githubusercontent.com/yrevar/942d3a0ac09ec9e5eb3a/raw/238f720ff059c1f82f368259d1ca4ffa5dd8f9f5/imagenet1000_clsidx_to_labels.txt' path = get_file(url) with open(path, 'r') as f: labels = eval(f.read()) return labels
def download_mnist(self): for v in MNIST.key_file.values(): get_file(MNIST.url_base + v)