Error ! MNIST.npz is not UTF-8 encoded error saving disabled

huangapple go评论57阅读模式
英文:

Error ! MNIST.npz is not UTF-8 encoded error saving disabled

问题

当我想在Jupyter中加载MNIST.npz格式的数据集时,我使用以下代码来加载文件,但出现了以下错误,显示我的文件不存在:[FileNotFoundError: [Errno 2] No such file or directory: 'MNIST_data/mnist.npz']。当我从我的文件中检查它并尝试打开它时,出现了另一个错误,提示mnist.npz不是UTF-8编码,保存被禁用了。

我该如何修复它?请帮助我。

我在Jupyter中的代码:

import numpy as np
path = "MNIST_data/mnist.npz"
with np.load(path, allow_pickle=True) as f:
   print(type(f))
   x_train, y_train = f['x_train'], f['y_train']
   x_test, y_test = f['x_test'], f['y_test']
英文:

When I want to load the MNIST.npz dataset with this format (mnist. npz) in Jupyter; I use from below codes to load the file but this error appeared that showed my file does not exist [FileNotFoundError: [Errno 2] No such file or directory: 'MNIST_data/mnist.npz'].
When I checked it from my files and tried to open it, another error appeared that said mnist.npz is not UTF-8 encoded saving disabled.

How can I fix it? Help me pls.

My codes in Jupyter:

import numpy as np
path = "MNIST_data/mnist.npz"
with np.load(path, allow_pickle=True) as f:
   print(type(f))
   x_train, y_train = f\['x_train'\], f\['y_train'\]
   x_test, y_test = f\['x_test'\], f\['y_test'\]

答案1

得分: 0

The MNIST.npz dataset with npz format is not UTF-8 encoding and for that reason, I couldn't load it with the codes which I shared in my question box. But finally, I found the solution; If you want to solve the error you should use 'ASCII' encoding like the below codes:

import numpy as np
path = "File address in your system"
with np.load(path, allow_pickle=True, encoding='ASCII' ) as f:
  print(type(f))
  x_train, y_train = f['x_train'], f['y_train']
  x_test, y_test = f['x_test'], f['y_test']

Good luck

英文:

The MNIST.npz dataset with npz format is not UTF-8 encoding and for that reason, I couldn't load it with the codes which I shared in my question box. But finally, I found the solution; If you want to solve the error you should use 'ASCII' encoding like the below codes:

import numpy as np
path = "File address in your system"
with np.load(path, allow_pickle=True, encoding='ASCII' ) as f:
  print(type(f))
  x_train, y_train = f\['x_train'\], f\['y_train'\]
  x_test, y_test = f\['x_test'\], f\['y_test'\]

Good luck

huangapple
  • 本文由 发表于 2023年6月25日 21:08:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76550553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定