在读这份代码前,首先我已经安装好最新版Anaconda,自带jupyter notebook.
在cmd窗口直接输入 jupyter notebook
可以在浏览器打开
(附注怎么下载到课程的作业代码,知乎主页上的链接已经失效了,可以直接前往官网http://cs231n.stanford.edu/index.html,进入他的courses note http://cs231n.github.io/)
点击Upload把knn.ipynb读上来。
# Run some setup code for this notebook.
import sys #我这里添加3行代码,否则找不到data_utils模块,添加的就是下载到的文件夹放置路径
sys.path.append('E:\\CZU\\assignment1\\cs231n')
print (sys.path)
import random
import numpy as np
from data_utils import load_CIFAR10 #这里也直接修改为模块的名字了
import matplotlib.pyplot as plt
from __future__ import print_function
# This is a bit of magic to make matplotlib figures appear inline in the notebook
# rather than in a new window.
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
# Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
# Load the raw CIFAR-10 data. #装载数据集
cifar10_dir = 'E:\CZU\cifar-10-python\cifar-10-batches-py' #修改路径为自己下载好的cifar-10数据集所在路径
X_train, y_train, X_test, y_test = load_CIFAR10(cifar10_dir)
# As a sanity check, we print out the size of the training and test data.
print('Training data shape: ', X_train.shape)
print('Training labels shape: ', y_train.shape)
print('Test data shape: ', X_test.shape)
print('Test labels shape: ', y_test.shape)
此前我已经通过另外的代码单独了解了一下cifar-10数据集,读出来以后是字典类型
# Visualize some examples from the dataset. #看一下数据集的部分内容做个示例
# We show a few examples of training images from each class.
classes = ['plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
nu