• 大小: 12.46MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-25
  • 语言: 其他
  • 标签: 深度学习  李飞飞  

资源简介

搬运的最新的2017 spring cs231n 课后编程作业,对学习深度学习很有用

资源截图

代码片段和文件信息

from __future__ import print_function

from six.moves import cPickle as pickle
import numpy as np
import os
from scipy.misc import imread
import platform

def load_pickle(f):
    version = platform.python_version_tuple()
    if version[0] == ‘2‘:
        return  pickle.load(f)
    elif version[0] == ‘3‘:
        return  pickle.load(f encoding=‘latin1‘)
    raise ValueError(“invalid python version: {}“.format(version))

def load_CIFAR_batch(filename):
  “““ load single batch of cifar “““
  with open(filename ‘rb‘) as f:
    datadict = load_pickle(f)
    X = datadict[‘data‘]
    Y = datadict[‘labels‘]
    X = X.reshape(10000 3 32 32).transpose(0231).astype(“float“)
    Y = np.array(Y)
    return X Y

def load_CIFAR10(ROOT):
  “““ load all of cifar “““
  xs = []
  ys = []
  for b in range(16):
    f = os.path.join(ROOT ‘data_batch_%d‘ % (b ))
    X Y = load_CIFAR_batch(f)
    xs.append(X)
    ys.append(Y)    
  Xtr = np.concatenate(xs)
  Ytr = np.concatenate(ys)
  del X Y
  Xte Yte = load_CIFAR_batch(os.path.join(ROOT ‘test_batch‘))
  return Xtr Ytr Xte Yte


def get_CIFAR10_data(num_training=49000 num_validation=1000 num_test=1000
                     subtract_mean=True):
    “““
    Load the CIFAR-10 dataset from disk and perform preprocessing to prepare
    it for classifiers. These are the same steps as we used for the SVM but
    condensed to a single function.
    “““
    # Load the raw CIFAR-10 data
    cifar10_dir = ‘cs231n/datasets/cifar-10-batches-py‘
    X_train y_train X_test y_test = load_CIFAR10(cifar10_dir)
        
    # Subsample the data
    mask = list(range(num_training num_training + num_validation))
    X_val = X_train[mask]
    y_val = y_train[mask]
    mask = list(range(num_training))
    X_train = X_train[mask]
    y_train = y_train[mask]
    mask = list(range(num_test))
    X_test = X_test[mask]
    y_test = y_test[mask]

    # Normalize the data: subtract the mean image
    if subtract_mean:
      mean_image = np.mean(X_train axis=0)
      X_train -= mean_image
      X_val -= mean_image
      X_test -= mean_image
    
    # Transpose so that channels come first
    X_train = X_train.transpose(0 3 1 2).copy()
    X_val = X_val.transpose(0 3 1 2).copy()
    X_test = X_test.transpose(0 3 1 2).copy()

    # Package data into a dictionary
    return {
      ‘X_train‘: X_train ‘y_train‘: y_train
      ‘X_val‘: X_val ‘y_val‘: y_val
      ‘X_test‘: X_test ‘y_test‘: y_test
    }
    

def load_tiny_imagenet(path dtype=np.float32 subtract_mean=True):
  “““
  Load TinyImageNet. Each of TinyImageNet-100-A TinyImageNet-100-B and
  TinyImageNet-200 have the same directory structure so this can be used
  to load any of them.

  Inputs:
  - path: String giving path to the directory to load.
  - dtype: numpy datatype used to load the data.
  - subtract_mean: Whether to subtract the mean training image.

  Returns: A dictionary with the following entries:
  - class_names: A list where class_na

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-11 17:26  CS231-master\
     文件        2729  2017-09-11 17:26  CS231-master\README.md
     文件          26  2017-09-11 17:26  CS231-master\_config.yml
     目录           0  2017-09-11 17:26  CS231-master\assignment1\
     文件         130  2017-09-11 17:26  CS231-master\assignment1\README.md
     文件        2743  2017-09-11 17:26  CS231-master\assignment1\Untitled.ipynb
     文件         169  2017-09-11 17:26  CS231-master\assignment1\collectSubmission.sh
     目录           0  2017-09-11 17:26  CS231-master\assignment1\cs231n\
     目录           0  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\
     文件         167  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\__init__.cpython-36.pyc
     文件        7083  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\data_utils.cpython-36.pyc
     文件        4401  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\features.cpython-36.pyc
     文件        3693  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\gradient_check.cpython-36.pyc
     文件        2328  2017-09-11 17:26  CS231-master\assignment1\cs231n\__pycache__\vis_utils.cpython-36.pyc
     目录           0  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\
     文件         103  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__init__.py
     目录           0  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\
     文件         281  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\__init__.cpython-36.pyc
     文件        4977  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\k_nearest_neighbor.cpython-36.pyc
     文件        4234  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\linear_classifier.cpython-36.pyc
     文件        2267  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\linear_svm.cpython-36.pyc
     文件        6538  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\neural_net.cpython-36.pyc
     文件        2269  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\__pycache__\softmax.cpython-36.pyc
     文件        8250  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\k_nearest_neighbor.py
     文件        6217  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\linear_classifier.py
     文件        5312  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\linear_svm.py
     文件       11183  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\neural_net.py
     文件        3953  2017-09-11 17:26  CS231-master\assignment1\cs231n\classifiers\softmax.py
     文件        7782  2017-09-11 17:26  CS231-master\assignment1\cs231n\data_utils.py
     目录           0  2017-09-11 17:26  CS231-master\assignment1\cs231n\datasets\
     文件         134  2017-09-11 17:26  CS231-master\assignment1\cs231n\datasets\get_datasets.sh
............此处省略132个文件信息

评论

共有 条评论