我正在創(chuàng)建一個 CNN,它使用 14 個可以共存的不同類別對 CXR 進行多標(biāo)簽分類。( https://stanfordmlgroup.github.io/competitions/cheexpert/ )。我將 Python 與 Keras 和 Tensorflow 一起使用,現(xiàn)在我正在嘗試讓代碼工作(使用小型測試 CNN),但我收到錯誤“ValueError:logits 和標(biāo)簽必須具有相同的形狀((None,14)vs(無,1))”我使用了具有二元交叉熵?fù)p失的 sigmoid 激活函數(shù)。我認(rèn)為創(chuàng)建訓(xùn)練和驗證數(shù)據(jù)集可能會出現(xiàn)問題。如圖所示,我將 ImageDataGenerator.flow_from_dataframe 函數(shù)與 pandas 數(shù)據(jù)框一起使用,所有 14 個標(biāo)簽(0 或 1)都有一列。 熊貓數(shù)據(jù)框結(jié)構(gòu)我在 stackoverflow/github 上搜索了同樣的問題,但他們大多不使用 ImageDataGenerator 并且必須調(diào)整 X 或 Y 的大小,但我不知道我將如何做到這一點。有誰知道出了什么問題?提前致謝!我的代碼如下。import pandas as pdimport tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras.preprocessing.image import ImageDataGeneratorfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Dense, Dropout, Activation, Flattenfrom tensorflow.keras.layers import Conv2D, MaxPooling2Dfrom tensorflow.keras.callbacks import TensorBoardimport timeimport h5pydf = pd.read_csv('D:\\Milou\\CheXpert-v1.0-small\\train.csv', usecols = [0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18])df = df.fillna(0) # Change NaN values to 0df = df.convert_dtypes() # Change datatypes from float to integer if possibledf = df.replace({-1 : 0}) # Regard the uncertain labels '-1' as negativeprint(df.head(5))label_names = ["No Finding", "Enlarged Cardiomediastinum", "Cardiomegaly", "Lung Opacity", "Lung Lesion", "Edema", "Consolidation", "Pneumonia", "Atelectasis", "Pneumothorax", "Pleural Effusion", "Pleural Other", "Fracture", "Support Devices"]datagen=ImageDataGenerator(rescale=1./255, validation_split=0.2)第一次在 stackoverflow 上提問,所以請不要猶豫,就缺少的信息等提供反饋!
3 回答

呼如林
TA貢獻1798條經(jīng)驗 獲得超3個贊
因為你有 2 個不同的類別,你應(yīng)該在你的最后dense
一層有 2 個神經(jīng)元,而不是你有觀察的數(shù)量。不應(yīng)在您的神經(jīng)網(wǎng)絡(luò)架構(gòu)中指定觀察次數(shù)。

月關(guān)寶盒
TA貢獻1772條經(jīng)驗 獲得超5個贊
使用 class_mode = 'raw' 如下:
train_generator=datagen.flow_from_dataframe(dataframe=df, directory="D:\\Milou", x_col="Path", y_col=label_names, subset="training", class_mode="raw", target_size=(100,100), batch_size=64)

慕娘9325324
TA貢獻1783條經(jīng)驗 獲得超4個贊
你需要在最后一層之前展平你的網(wǎng)絡(luò),因為這種不展平的輸入你會得到所有這些類型的錯誤。實際上在最后一層你傳遞的是多維數(shù)組
tf.keras.layers.Flatten()
添加回答
舉報
0/150
提交
取消