第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Python中為深度學(xué)習(xí)準(zhǔn)備數(shù)據(jù)

如何在Python中為深度學(xué)習(xí)準(zhǔn)備數(shù)據(jù)

慕工程0101907 2023-10-05 16:45:51
我已經(jīng)完成了 Kaggle learn 的深度學(xué)習(xí)課程,并開始為 MNIST Digit 數(shù)據(jù)集編寫模型。我喜歡理解我所學(xué)的代碼,并且我遇到過這一點(diǎn):def data_prep(raw):    out_y = keras.utils.to_categorical(raw.label, num_classes)    num_images = raw.shape[0]    x_as_array = raw.values[:,1:]    x_shaped_array = x_as_array.reshape(num_images, img_rows, img_cols, 1)    out_x = x_shaped_array / 255    return out_x, out_y這部分真的讓我很困惑。我不明白其中大部分內(nèi)容。有人可以逐步解釋每行代碼的作用嗎?如果我要在具有多種顏色的彩色圖像上執(zhí)行此操作,這會如何工作?我知道這有點(diǎn)寬泛。稍后,我要做一些涉及彩色圖像的事情,但我不確定該怎么做,因?yàn)槲铱梢钥吹胶诎住皡?shù)”(數(shù)組形狀中的 1,除以255)旁注:raw是一個 pandas 數(shù)據(jù)框
查看完整描述

1 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個贊

在每行上方添加注釋以解釋其目的:


#input is a 2D dataframe of images

def data_prep(raw):

? ? #convert the classes in raw to a binary matrix

? ? #also known as one hot encoding and is typically done in ML

? ? out_y = keras.utils.to_categorical(raw.label, num_classes)


? ? #first dimension of raw is the number of images; each row in the df represents an image

? ? num_images = raw.shape[0]


? ? #remove the first column in each row which is likely a header and convert the rest into an array of values

? ? #ML algorithms usually do not take in a pandas dataframe?

? ? x_as_array = raw.values[:,1:]


? ? #reshape the images into 3 dimensional

? ? #1st dim: number of images

? ? #2nd dim: height of each image (i.e. rows when represented as an array)

? ? #3rd dim: width of each image (i.e. columns when represented as an array)

? ? #4th dim: the number of pixels which is 3 (RGB) for colored images and 1 for gray-scale images

? ? x_shaped_array = x_as_array.reshape(num_images, img_rows, img_cols, 1)


? ? #this normalizes (i.e. 0-1) the image pixels since they range from 1-255.?

? ? out_x = x_shaped_array / 255


? ? return out_x, out_y

要處理彩色圖像,數(shù)組中的第四個維度的大小應(yīng)為 3,表示RGB 值。


查看完整回答
反對 回復(fù) 2023-10-05
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號