问题描述
我有一个深度学习课程的作业,并且他们提供了Jupyter笔记本作为基本代码,问题是在运行数据导入和重塑后,Jupyter笔记本通过内存错误",经过一些分析后尝试在普通的.py文件中编译相同的代码,一切运行良好.
I have an assignment for a Deep Learning class, and they provide a Jupyter notebook as a base code, the thing is that after running the data import and reshape, jupyter notebook through a "Memory Error", after some analysis y tried to compile the same code in a normal .py file, and everything runs well.
问题是(最好)我需要使用Jupyter笔记本作为开发的基础,因为对于这类任务而言,交互性更高.
The thing is that I'm required (preferably) to use the Jupyter notebook as the base for development, since is more interactive for the kind of task.
<ipython-input-2-846f80a40ce2> in <module>()
2 # Load the raw CIFAR-10 data
3 cifar10_dir = 'datasets\\'
----> 4 X, y = load_CIFAR10(cifar10_dir)
C:\path\data_utils.pyc in load_CIFAR10(ROOT)
18 f = os.path.join(ROOT, 'cifar10_train.p')
19 print('Path: ' + f );
---> 20 Xtr, Ytr = load_CIFAR_batch(f)
21 return Xtr, Ytr
22
C:\path\data_utils.pyc in load_CIFAR_batch(filename)
10 X = np.array(datadict['data'])
11 Y = np.array(datadict['labels'])
---> 12 X = X.reshape(-1, 3, 32, 32).transpose(0,2,3,1).astype("float")
13 return X, Y
14
MemoryError:
该错误发生在第12行中,我知道这是一个占用内存的分配,但这并不意味着4 GB的RAM就足够了,而当代码在Jupyter外部运行时没有问题时就可以确认这一点.
The error occurs in the line 12, i know is a memory consuming assignment, but that doesn't mean that 4 GB of RAM wont suffice, and that was confirmed when the code run without problems outside Jupyter.
我的猜测是,它与Jupyter或Chrome的内存限制有关,但我不确定,也不知道如何解决.
My Guess is it has something to do with the memory limit either by Jupyter or by Chrome, but I'm not sure and also dont know how to solve it.
顺便说一句:
- 我有一台具有4GB RAM的Windows 10笔记本电脑
- 和Chrome版本57.0.2987.133(64位)
推荐答案
我距离这个问题仅一年零两个月.关于原因的技术答案在这里得到了很好的解释:
I am only a year and 2 months late to this question. The technical answer as to why is really nicely explained here: https://superuser.com/questions/372881/is-there-a-technical-reason-why-32-bit-windows-is-limited-to-4gb-of-ram
这也暗示了conda解决方案起作用的原因.
It also implies why the conda solution works.
但是对于懒惰的工程师来说,不变的解决方法是,关闭并非绝对必要的Chrome选项卡,然后重新启动内核,以便重新启动.
But for a lazy engineer's no-change workaround, close the Chrome tabs not absolutely necessary and restart your kernel so it starts afresh.
Kernel > Restart (& Run All)
这篇关于Jupyter Notebook(仅)内存错误,相同的代码在常规.py中运行并且可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!