簡體   English   中英

VSCode中的“ MemoryError”,但Jupyter / AnacondaPrompt中沒有

[英]“MemoryError” in VSCode but not in Jupyter/AnacondaPrompt

我在MNIST數據集上的split_train_test函數的Python實現中遇到了大約2 GB的MemoryError。

任務管理器幾乎無法達到最大內存的50%,包括在我的計算機上打開的其他應用程序。 我有16GB的RAM。

我看到大多數人都指向64 vs 32位或python 2 vs 3問題。 但是,我的VS Code和Windows 10都是64位的,並查看>命令面板> Python:選擇解釋器顯示我正在使用anaconda3 / conda的Python 3.7.1 64位。

我知道代碼本身可以工作,因為導入py文件后,我已經在Jupyter中使用了輸出。

    def split_train_val(val_frac=0.3, size=1):
        """Splits training and validation set

        param val_frac: fraction of total training set to be used for validation
        """
        # Read converted csv
        X_raw = pd.read_csv('Data/csv/X_train.csv')
        Y_raw = pd.read_csv('Data/csv/y_train.csv')

        # Rename Label column, concat to X set
        Y_raw.columns = ['Label']
        df = pd.concat([Y_raw, X_raw], axis=1).sample(frac=size)

        # Split training set into train and val
        N = df.shape[0] 
        n = round(val_frac * N)
        train = df.iloc[n:,:]
        val = df.iloc[:n,:]

        x_train = train.drop(['Label'], axis=1)
        x_val = val.drop(['Label'], axis=1)
        y_train = train.Label
        y_val = val.Label


        # Return training and validation set
        return(x_train, y_train, x_val, y_val)


    x_train, y_train, x_val, y_val = split_train_val()

錯誤信息:

Traceback (most recent call last):
  File "preprocessing.py", line 71, in <module>
    x_train, y_train, x_val, y_val = split_train_val()
  File "preprocessing.py", line 53, in split_train_val
    df = pd.concat([Y_raw, X_raw], axis=1).sample(frac=size)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\reshape\concat.py", line 229, in concat
    return op.get_result()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\reshape\concat.py", line 426, in get_result
    copy=self.copy)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\internals\managers.py", line 2052, in concatenate_block_managers
    values = values.copy()
MemoryError

最后,我嘗試按照某些VS Code文檔的建議將jedi.memoryLimit設置更改為-1。 這也沒有幫助。

我導入然后在Jupyter中運行該功能。 我也在Anaconda Prompt中運行了此確切代碼。 它們均不會導致任何錯誤。

VS Code和Windows 10可能是64位的,但是Python的安裝是32位的,如路徑所示: C:\\Users\\...\\AppData\\Local\\Programs\\Python\\Python37-32\\ 嘗試顯式安裝Python的64位版本,並確保在VS Code中選擇它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM