为什么图片不显示且索引没有变化?

时间:2018-11-17 17:19:31

标签: python numpy matplotlib neural-network h5py

我正在尝试从Coursera做一个简单的练习,在那里我必须建立一个神经网络。在此过程中,我遇到了两个问题:

  1. 如何显示下面的图像?
  2. 最后一行的索引不变,始终为零!我希望它取值为66

这是我正在考虑的代码:

def load_dataset():
    with h5py.File('train_catvnoncat.h5', "r") as train_dataset:
        train_set_x_orig = np.array(train_dataset["train_set_x"][:])
        train_set_y_orig = np.array(train_dataset["train_set_y"][:])

    with h5py.File('test_catvnoncat.h5', "r") as test_dataset:
        test_set_x_orig = np.array(test_dataset["test_set_x"][:])
        test_set_y_orig = np.array(test_dataset["test_set_y"][:])
        classes = np.array(test_dataset["list_classes"][:])

    train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
    test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))

    return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes


train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()
# Example of a picture

index =66
plt.imshow(train_set_x_orig[index])
print ("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode("utf-8") +  "' picture.")

当我运行代码时,没有任何变化,并且保持索引为0。

输出:

y = [0], it's a 'non-cat' picture.

0 个答案:

没有答案