我最近参加CS231n在线课程。尝试使用CIFAR-10数据集在http://cs231n.github.io/classification/
中实现简单的图像分类代码在运行此代码时,在预测功能上,时间过长,甚至没有完成。我基本上复制并粘贴了所有代码。 我的桌面拥有最先进的机器。
代码如下所示。
class NearestNeighbor:
def __init__(self):
pass
def train(self, X, y):
"""X is N x D where each row is an example. Y is 1-dimension of size N"""
# the nearest neighbor classifier simply remembers all the training data
self.Xtr = X
self.ytr = y
def predict(self, X):
"""X is N x D where each row is an example we wish to predict label for"""
num_test = X.shape[0]
# lets make sure that the output type matches the input type
Ypred = np.zeros(num_test, dtype = self.ytr.dtype)
# loop over all test rows
for i in xrange(num_test):
# find the nearest training image to the i'th test image
# using the L1 distance (sum of absolute value differences)
distances = np.sum(np.abs(self.Xtr - X[i,:]), axis = 1)
min_index = np.argmin(distances) # get the index with smallest distance
Ypred[i] = self.ytr[min_index] # predict the label of the nearest example
return Ypred
Xtr, Ytr, Xte, Yte = load_CIFAR10('/home/tegg/Downloads/cifar-10-batches-py/')
# flatten out all images to be one-dimensional
Xtr_rows = Xtr.reshape(Xtr.shape[0], 32*32*3) # Xtr_rows become 50000 x 3072
Xte_rows = Xte.reshape(Xte.shape[0], 32*32*3) # Xte_rows become 10000 x 3072
nn = NearestNeighbor() # create a Nearest Neighbor classifier class
nn.train(Xtr_rows, Ytr) # train the classifier on the training images and labels
Yte_predict = nn.predict(Xte_rows) # predict labels on the test images
# and now print the classification accuracy, which is the average number
# of examples that are correctly predicted (i.e. label matches)
Yte_predict = nn.predict(Xte_rows)
我认为最后一行遇到了麻烦。
import {test} from "tape";
import {default as nightmare} from "nightmare";
const page = nightmare().goto("http://localhost:4000/index.html");
page.evaluate(() => document.getElementsByTagName("body").length).end()
.then((result) => {
test("detect page body", (assert) => {
assert.equal(1, result);
assert.end();
});
});
使用ipython notebook运行此代码时,它会继续运行代码,而不显示结果(完成编译)。我的代码有什么问题吗?