资源简介
CS231N作业例程源码,斯坦福机器学习李飞飞课程课后作业
代码片段和文件信息
import cPickle as pickle
import numpy as np
import os
from scipy.misc import imread
def load_CIFAR_batch(filename):
“““ load single batch of cifar “““
with open(filename ‘rb‘) as f:
datadict = pickle.load(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 load_tiny_imagenet(path dtype=np.float32):
“““
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.
Returns: A tuple of
- class_names: A list where class_names[i] is a list of strings giving the
WordNet names for class i in the loaded dataset.
- X_train: (N_tr 3 64 64) array of training images
- y_train: (N_tr) array of training labels
- X_val: (N_val 3 64 64) array of validation images
- y_val: (N_val) array of validation labels
- X_test: (N_test 3 64 64) array of testing images.
- y_test: (N_test) array of test labels; if test labels are not available
(such as in student code) then y_test will be None.
“““
# First load wnids
with open(os.path.join(path ‘wnids.txt‘) ‘r‘) as f:
wnids = [x.strip() for x in f]
# Map wnids to integer labels
wnid_to_label = {wnid: i for i wnid in enumerate(wnids)}
# Use words.txt to get names for each class
with open(os.path.join(path ‘words.txt‘) ‘r‘) as f:
wnid_to_words = dict(line.split(‘\t‘) for line in f)
for wnid words in wnid_to_words.iteritems():
wnid_to_words[wnid] = [w.strip() for w in words.split(‘‘)]
class_names = [wnid_to_words[wnid] for wnid in wnids]
# Next load training data.
X_train = []
y_train = []
for i wnid in enumerate(wnids):
if (i + 1) % 20 == 0:
print ‘loading training data for synset %d / %d‘ % (i + 1 len(wnids))
# To figure out the filenames we need to open the boxes file
boxes_file = os.path.join(path ‘train‘ wnid ‘%s_boxes.txt‘ % wnid)
with open(boxes_file ‘r‘) as f:
filenames = [x.split(‘\t‘)[0] for x in f]
num_images = len(filenames)
X_train_block = np.zeros((num_images 3 64 64) dtype=dtype)
y_train_block = wnid_to_label[wnid] * np.ones(num_images dtype=np.int64)
for j img_file in enumerate(filenames):
img_file = os.path.join(path ‘train‘ wnid ‘images‘ img_file)
img = imread(img_file)
if img.ndim == 2:
## grayscale file
img.shape
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-26 08:57 cs231n-master\
文件 1137 2017-12-26 08:57 cs231n-master\README.md
目录 0 2017-12-26 08:57 cs231n-master\assignment1\
文件 19 2017-12-26 08:57 cs231n-master\assignment1\.gitignore
目录 0 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\
文件 361514 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\features-checkpoint.ipynb
文件 410304 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\knn-checkpoint.ipynb
文件 67588 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\softmax-checkpoint.ipynb
文件 352222 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\svm-checkpoint.ipynb
文件 756677 2017-12-26 08:57 cs231n-master\assignment1\.ipynb_checkpoints\two_la
文件 130 2017-12-26 08:57 cs231n-master\assignment1\README.md
文件 160 2017-12-26 08:57 cs231n-master\assignment1\collectSubmission.sh
目录 0 2017-12-26 08:57 cs231n-master\assignment1\cs231n\
文件 0 2017-12-26 08:57 cs231n-master\assignment1\cs231n\__init__.py
目录 0 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\
文件 103 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\__init__.py
文件 8198 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\k_nearest_neighbor.py
文件 5611 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\linear_classifier.py
文件 4564 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\linear_svm.py
文件 10949 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\neural_net.py
文件 3187 2017-12-26 08:57 cs231n-master\assignment1\cs231n\classifiers\softmax.py
文件 5550 2017-12-26 08:57 cs231n-master\assignment1\cs231n\data_utils.py
目录 0 2017-12-26 08:57 cs231n-master\assignment1\cs231n\datasets\
文件 88 2017-12-26 08:57 cs231n-master\assignment1\cs231n\datasets\.gitignore
文件 134 2017-12-26 08:57 cs231n-master\assignment1\cs231n\datasets\get_datasets.sh
文件 4807 2017-12-26 08:57 cs231n-master\assignment1\cs231n\features.py
文件 3568 2017-12-26 08:57 cs231n-master\assignment1\cs231n\gradient_check.py
文件 1951 2017-12-26 08:57 cs231n-master\assignment1\cs231n\vis_utils.py
文件 361514 2017-12-26 08:57 cs231n-master\assignment1\features.ipynb
文件 412 2017-12-26 08:57 cs231n-master\assignment1\fr
文件 410304 2017-12-26 08:57 cs231n-master\assignment1\knn.ipynb
............此处省略80个文件信息
- 上一篇:awr使用教程
- 下一篇:汇编语言_王爽_Word文字版
相关资源
- 通信原理labview代码1.zip
- 军队文职资料.zip
- RH1288 V2-BIOS-V520.zip
- CTP接口及开发文档.zip
- qsv转MP4.zip
- 上下位机程序源码.zip
- stm32驱动MAX7219控制数码管显示.zip
- diffpdf.zip pdf对比工具
- qb支付打包.zip
- 实训项目四PowerPoint 综合应用答案.z
- 《MapReduce2.0源码分析与实战编程》.
- 2020个人征信报告模板.zip
- 手势刷抖音32单片机代码.zip
- AMTEmu Win v0.9.2.zip
- Xsteel自动调图软件中文版.zip
- [Orbit国外资源利器.].OrbitDownloaderSetu
- protoc-3.11.4-win64.zip
- (D)基于NTC热敏电阻的温度计.zip
- VSP_Manual.zip
- 基于STM32 HAL库的定时任务调度器例程
- 录屏软件(1).zip
- 空间数据库-空间查询实验包.zip
- 西北工业大学信号与系统实验课实验
- 基于STM32和arduino的MPU9250九轴传感器代
- 通信原理实验教程.zip
- stm32f103c8t6蓝牙运动控制.zip
- 哈尔滨建筑shp数据.zip
- 实时数据&车辆路径导航功能.zip
- TCRT5000红外反射传感器循迹传感器.z
- 20套CCIE实验pdf版拓扑,需求,解法,
评论
共有 条评论