細(xì)節(jié):Python 3.7.1,Mac OS High Sierra 10.13.6。我正在使用 IDLE 并通過終端運(yùn)行程序。我最近在 MNIST 手寫數(shù)字上取得了成功,現(xiàn)在我正在嘗試用我自己的數(shù)據(jù)集訓(xùn)練一個生成對抗網(wǎng)絡(luò)。數(shù)據(jù)集是一個圖像文件夾。錯誤:Traceback (most recent call last): File "Pride.py", line 29, in <module> listing = os.listdir(path1) FileNotFoundError: [Errno 2] No such file or directory: 'Users/darren/Desktop/Pride'我已經(jīng)查看了有關(guān)此問題的其他線程,但不明白我的路徑有什么問題,所以如果我的錯誤是由于一些簡單的原因,我深表歉意。我從終端執(zhí)行的 Python 文件和我的數(shù)據(jù)集文件夾都在我的桌面上。到目前為止,這是我的代碼:from keras.models import Sequentialfrom keras.layers.core import Dense, Dropout, Activation, Flattenfrom keras.layers.convolutional import Convolution2D, MaxPooling2Dfrom keras.optimizers import SGD,RMSprop,adamfrom keras.utils import np_utilsimport numpy as npimport matplotlib.pyplot as pltimport matplotlibimport osimport theanofrom PIL import Imagefrom numpy import *from sklearn.utils import shufflefrom sklearn.model_selection import train_test_split# input image dimensionsimg_rows, img_cols = 200, 200# number of channelsimg_channels = 1#%%# datapath1 = "Users/darren/Desktop/Pride" #path of folder of images path2 = "Users/darren/Desktop/Prideresized" #path of folder to save imageslisting = os.listdir(path1) num_samples=size(listing)print ("num_samples")for file in listing: im = Image.open(path1 + '\\' + file) img = im.resize((img_rows,img_cols)) gray = img.convert('L') gray.save(path2 +'\\' + file, "JPEG")
2 回答

慕妹3146593
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個贊
在 mac os 中,如果您將數(shù)據(jù)集文件或任何其他文件保存在文檔文件夾中,則該文件路徑的代碼可能如下所示
melbourne_file_path = **'/Users/adi/Documents/Top250.csv'**
melbourne_data = pd.read_csv(melbourne_file_path)
melbourne_data.describe()

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個贊
如果您使用相對路徑(不以 a 開頭的路徑/),您需要更改它們,使它們與腳本的位置相關(guān)。
在你的情況下:
path1 = "Pride" #path of folder of images
path2 = "Prideresized" #path of folder to save images
添加回答
舉報(bào)
0/150
提交
取消