我将Windows 10,Keras(2.3.1版)和Tensorflow(2.1.0版)与CUDA(10.1版,V10.1.243版)结合使用,以训练20个残差网络模型,涉及20个主题的数据。
不幸的是,对于模型 k (k <20),训练在第一个时期随机停止。有时k = 3,有时k = 7,有时k = 19。我得到的唯一输出是以下内容:
Train on 50634 samples, validate on 5626 samples
Epoch 1/200
CPU工作负载始终保持在20%(如果允许的话,甚至持续数天),而GPU工作负载则停留在1%。从任务管理器可以看出,导致这种工作量的任务是 Python 。我已经尝试添加以下代码,但没有成功:
import tensorflow as tf
configproto = tf.compat.v1.ConfigProto()
configproto.gpu_options.allow_growth = True
sess = tf.compat.v1.Session(config=configproto)
tf.compat.v1.keras.backend.set_session(sess)
任何想法都受到高度赞赏。
这是我的训练循环的摘要:
for testSubjectID in patientIDsForTesting:
[testX,testY,trainX,trainY] = PrepareData.groupAndReturnDataAndBinaryAnnotationsForCurrentSubject()
[scaledTrainX,scaledTestX] = PrepareData.scaleTrainingAndTestingData(trainX,testX)
x_trainScaledWithoutValidationSet,x_validTrainScaled,y_trainWithoutValidationSet,y_validTrain = train_test_split(scaledTrainX,trainY,test_size=0.1,shuffle= True)
nb_classes = len(np.unique(np.concatenate((trainY,testY),axis =0)))
y_true = np.array(testY, dtype=np.int64)
y_trainWithoutValidationSetNumpyArray = np.array(y_trainWithoutValidationSet)
testYNumpyArray = np.array(testY)
y_validTrainNumpyArray = np.array(y_validTrain)
trainXNumpyArray = np.array(trainX)
enc = sklearn.preprocessing.OneHotEncoder()
enc.fit(np.concatenate((y_trainWithoutValidationSetNumpyArray,testY),axis =0).reshape(-1,1))
y_trainWithoutValidationSet = enc.transform(y_trainWithoutValidationSetNumpyArray.reshape(-1,1)).toarray()
y_test = enc.transform(testYNumpyArray.reshape(-1,1)).toarray()
y_valid = enc.transform(y_validTrainNumpyArray.reshape(-1,1)).toarray()
scaledTestX = scaledTestX.reshape((scaledTestX.shape[0],scaledTestX.shape[1],1))
x_validScaled = x_validTrainScaled.reshape((x_validTrainScaled.shape[0],x_validTrainScaled.shape[1],1))
input_shape = x_trainScaledWithoutValidationSet.shape[1:] #x_trainScaled.shape[1:]
Classifier = getResNetClassifier()
Classifier.fit(x_trainScaledWithoutValidationSet,y_trainWithoutValidationSet,x_validScaled,y_valid,y_true)