簡體   English   中英

為什么我的 Tensorflow CNN 的准確度為零而損失不是?

[英]why my Tensorflow CNN's accuracy is zero while loss is not?

我正在嘗試制作雙 CNN,我的數據庫有兩個輸入,它們最終合並在一起,一個神經元作為 IC50 的輸出。

當我嘗試這樣做時,我的准確度為 0,而損失還可以。 我是否使用了錯誤的損失函數? 它目前是mean_squared_error

操作系統:Windows10 tensorflow 版本:2.3.0

我的代碼”

encoded_drugs=np.load('encoded_drugs.npy')
encoded_cells=np.load('encoded_cells.npy')
encoded_ICs=np.load('encoded_ICs.npy')
encoded_drugs_train, encoded_drugs_test,encoded_cells_train, encoded_cells_test, encoded_ICs_train, encoded_ICs_test = train_test_split(encoded_drugs,encoded_cells, encoded_ICs, test_size=0.2)


input1=keras.layers.Input(shape=(139,32,))
x1=keras.layers.Flatten(input_shape=(139,32,))(input1)
x2=keras.layers.Dense(64,activation='relu')(x1)
x3=keras.layers.Dense(64,activation='relu')(x2)

input2=keras.layers.Input(shape=(735,2,))
y1=keras.layers.Flatten(input_shape=(735,2,))(input2)
y2=keras.layers.Dense(128,activation='relu')(y1)
y3=keras.layers.Dense(64,activation='relu')(y2)

merged=keras.layers.concatenate([x3,y3],axis=-1)

z=keras.layers.Dense(64,activation='relu')(merged)
out=keras.layers.Dense(1,activation='sigmoid')(z)

model=keras.models.Model(inputs=[input1,input2], outputs=out)

model.compile(optimizer='sgd',loss='mean_squared_error',metrics=['accuracy'])

model.fit([encoded_drugs_train,encoded_cells_train],encoded_ICs_train,validation_split = 0.2,epochs=2)

test_loss, test_accuracy= model.evaluate([encoded_drugs_test,encoded_cells_test],encoded_ICs_test)

print('Accuracy=', test_accuracy)

我的輸出:

2020-02-18 11:06:00.759824: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations:  AVX AVX2
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
2020-02-18 11:06:00.774869: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 4. Tune using inter_op_parallelism_threads for best performance.
Train on 75793 samples, validate on 18949 samples
Epoch 1/2
75793/75793 [==============================] - 17s 229us/sample - loss: 10.3671 - accuracy: 0.0000e+00 - val_loss: 10.4082 - val_accuracy: 0.0000e+00
Epoch 2/2
75793/75793 [==============================] - 11s 146us/sample - loss: 10.2673 - accuracy: 0.0000e+00 - val_loss: 10.3852 - val_accuracy: 0.0000e+00


3s 125us/sample - loss: 8.3239 - accuracy: 0.0000e+00
Accuracy= 0.0

您正在嘗試解決回歸問題(使用mean_squared_error損失),同時使用准確性作為指標。 在這種情況下,准確性不是有效的度量標准。

首先,確保您嘗試解決的問題確實是回歸或分類問題。

在回歸的情況下,使用Dense(1,activation='linear')作為最后一個輸出層,並使用model.compile(optimizer='sgd',loss='mean_squared_error',metrics=['mse'])

在分類的情況下,使用Dense(1,activation='sigmoid')作為最后的輸出層,並使用model.compile(optimizer='sgd',loss='binary_crossentropy',metrics=['accuracy'])

其次,您需要訓練更多的 epochs(29 秒確實不足以提供對結果的良好概述)。

暫無
暫無

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

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