# imgplot = plt.imshow(Y) # plt.show(block=False) # plt.pause(3) # plt.close() #hello = y_to.flatten() #print(hello[hello==3].shape) #print("Number of classes",np.unique(hello)) #class_weights = class_weight.compute_class_weight('balanced',np.unique(hello),hello) #class_weights.insert(3,0) #print("class_weights",class_weights) x_to = np.asarray(x_to) y_to = np.asarray(y_to) print(x_to.shape) print(y_to.shape) y_to[ y_to == 4] = 1 #since label 4 was missing in Brats dataset , changing all labels 4 to 3. #y_to = one_hot_encode(y_to) y_to[y_to == 2] = 1 y_to[y_to == 1] = 1 y_to[y_to == 0] = 0 print(y_to.shape) #y_to = y_to.reshape(240,240,1) model.fit(x=x_to, y=y_to, batch_size=20, epochs=50) model.save('2class.h5')
for j in range(100): flair_small[i, :, :, j] = flair_small_[i, :, :, j+36] print('Shape of flair_small: ' + str(flair_small.shape)) os.environ["CUDA_VISIBLE_DEVICES"] = "0, 1, 2, 3" tfconfig = tf.ConfigProto() tfconfig.gpu_options.allow_growth = True tfconfig.allow_soft_placement = True sess = tf.Session(config=tfconfig) sess.run(tf.global_variables_initializer()) keras.backend.set_session(sess) # history = model.fit(x=X_train_t1, y=X_train_t1, batch_size=32, epochs=100) # history = model.fit(x=X_train_t1ce, y=X_train_t1ce, batch_size=32, epochs=100) # history = model.fit(x=X_train_t2, y=X_train_t2, batch_size=32, epochs=100) history = model.fit(x=flair_small, y=flair_small, batch_size=32, epochs=100) print(history.history.keys()) plt.plot(history.history['loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train'], loc='upper right') plt.show() model.save("flair_model")