Chainer TypeError: Image data of dtype object cannot be converted to float

拼搏现实的明天。 2023-01-10 03:52 353阅读 0赞

网上一堆说看看路径什么的,感觉都在瞎扯淡。

可以试着type() 一下自己要imshow的变量,看看是不是数据类型不对应。

自己type了一下,结果发现自己要保存的变量压根就不是numpy的数组,而是chainer.Variable.variable的数据类型,使用该数据类型的data属性获得numpy数组。

  1. with chainer.no_backprop_mode() and chainer.using_config("train", False):
  2. y_onehot, z = model.encode_x_yz(images_test, apply_softmax_y=True)
  3. images_test_reconstruction = model.decode_yz_x(y_onehot, z)
  4. images_test_reconstruction = (images_test_reconstruction + 1.0) / 2.0
  5. images_test = (images_test + 1.0) / 2.0
  6. pylab.figure(figsize=(38,4))
  7. for n in range(num_clusters):
  8. #origal
  9. pylab.subplot(2, num_clusters, n+1)
  10. pylab.imshow(images_test[n*num_plots_per_cluster].reshape((image_width, image_height)), interpolation="none")
  11. pylab.gray()
  12. pylab.axis("off")
  13. #reconsruct
  14. image = images_test_reconstruction[n * num_plots_per_cluster].reshape((image_width, image_height))
  15. pylab.subplot(2, num_clusters, num_clusters+n+1)
  16. pylab.imshow(image.data, interpolation="none")
  17. pylab.gray()
  18. pylab.axis("off")
  19. fig = pylab.gcf()
  20. fig.set_dpi(720)
  21. pylab.savefig("clusters.png")
  22. pylab.close()

发表评论

表情:
评论列表 (有 0 条评论,353人围观)

还没有评论,来说两句吧...

相关阅读