为什么我的Tensorflow CNN准确率为零而损失不为零?

我正在尝试构建双子CNN,我的数据库有两个输入,最终合并在一起,输出为IC50的单个神经元。

当我尝试这样做时,我得到了0的准确率,而损失值是正常的。我是否使用了错误的损失函数?当前使用的是mean_squared_error

操作系统:Windows 10
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 AVX2To 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 samplesEpoch 1/275793/75793 [==============================] - 17s 229us/sample - loss: 10.3671 - accuracy: 0.0000e+00 - val_loss: 10.4082 - val_accuracy: 0.0000e+00Epoch 2/275793/75793 [==============================] - 11s 146us/sample - loss: 10.2673 - accuracy: 0.0000e+00 - val_loss: 10.3852 - val_accuracy: 0.0000e+003s 125us/sample - loss: 8.3239 - accuracy: 0.0000e+00Accuracy= 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'])

其次,您需要训练更多的轮次(29秒真的不足以提供对结果的全面了解)。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注