Skip to content

normalize之后_train_samples纬度会发生改变,不能直接用imshow #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

xinqiu
Copy link

@xinqiu xinqiu commented Oct 20, 2016

python2.7情况下,normalize直接用inspect会报错,维度问题
normalize之前_train_samples的纬度(73257, 32, 32, 3)
之后纬度为(73257, 32, 32, 1)
将其转化为(73257, 32, 32)即可画出图

python2.7情况下,normalize直接用inspect会报错,维度问题
normalize之前_train_samples的纬度(73257, 32, 32, 3)
之后纬度为(73257, 32, 32, 1)
将其转化为(73257, 32, 32)即可画出图
@CreatCodeBuild
Copy link
Owner

不应该直接修改 _train_samples,因为要在 TF 中使用 4 维的 Tensor。
应该在 Inspect 中判断 shape[3] 是否为 1。
imshow 接受的 shape 有 (x, y), (x, y, 3) and (x, y, 4)
如果shape[3] == 1, 那么 reshape

def inspect(dataset, labels, i):

# 显示图片看看

if dataset.shape[3] == 1:

    shape = dataset.shape

    dataset = dataset.reshape(shape[0], shape[1], shape[2])

print(labels[i])

plt.imshow(dataset[i])

plt.show()

@SMZCC
Copy link

SMZCC commented Aug 31, 2017

你好,为啥按照这个代码显示的灰度图还是有颜色啊?

@CreatCodeBuild
Copy link
Owner

@SMZCC 这是plt函数实现造成的。不是bug。不用在意。

@SMZCC
Copy link

SMZCC commented Sep 1, 2017

  • 蟹蟹,我知道了;
  • 另外,我发现,在plt.imshow(samples[i])中,添加第二个参数,plt.imshow(samples[i], plt.cm.gray)就会灰度显示了;
  • 可是,我还有个问题:我调用了inspect函数两次,理论来说应该会显示两个图片,然而,每次我都需要将第一张图片(3通道的图片)关闭掉才会显示第二张图片(单通道的),怎么让他们同时显示呢?

@CreatCodeBuild
Copy link
Owner

CreatCodeBuild commented Sep 1, 2017

@SMZCC 这个你可以google一下。matplotlib不是很易用。我之前遇到过同样的问题,但是忘记了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants