cs231n Assignment#1 (1)k-Nearest Neighbor (kNN) exercise 代码理解笔记

在读这份代码前,首先我已经安装好最新版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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值