file_sep = r'/' log_save_Path = Result_save_Path + file_sep[0] + 'log' model_save_Path = Result_save_Path + file_sep[0] + 'model' os.system('mkdir ' + log_save_Path) os.system('mkdir ' + model_save_Path) # 开始训练:一下代码由main改变而来,但是不需要保存模型 if __name__ == "__main__": # prepare container:准备网络输入输出容器 暂时测试新getbatch函数,所以注释掉了 # data_input_c = np.zeros([batch_size] + data_input_shape + [1], dtype=np.float32) # net input container # label_input_c = np.zeros([batch_size] + label_shape) # 构建网络并compile # d_model_1 = vgg16_w_3d(use_bias_flag=True,classes=2) d_model = resnet_or(use_bias_flag=False, classes=2) # d_model_1 = resnext(classes=2, use_bias_flag=True) # d_model_1 = SparseNetImageNet121(classes = 2,activation='softmax',dropout_rate = 0.5) # d_model_1 = se_dense_net(nb_layers=[6, 12, 24, 16], growth_rate=32, nb_filter=64, bottleneck=True, reduction=0.0, dropout_rate=None, subsample_initial_block=True) if multi_gpu_mode: d_model = multi_gpu_model(d_model, gpus=gpu_munum) # d_model.compile(optimizer=adam(lr=init_lr), loss='categorical_crossentropy', metrics=[y_t, y_pre, Acc]) d_model.compile(optimizer=SGD(lr=init_lr, momentum=0.9), loss='categorical_crossentropy', metrics=[y_t, y_pre, Acc]) # pause() # identify # print(d_model.summary()) # view net # pause() # identify # extra param initialization:初始化一些用来记录和显示的参数
import keras.backend as K from w_resnet import resnet_nobn, se_resnet, resnet_or import keras.backend as K # step2: import extra model finished # step2: import extra model finished os.environ["CUDA_VISIBLE_DEVICES"] = "1" config = tf.ConfigProto() config.gpu_options.allow_growth = True set_session(tf.Session(config=config)) # 構建網絡 model = resnet_or(use_bias_flag=True, classes=2) # model.compile(optimizer=SGD(lr=1e-6, momentum=0.9), loss='binary_crossentropy') # 構建輸入 data_input_c = np.zeros([1, 280, 280, 16, 1], dtype=np.float32) H5_file = h5py.File(r'/data/@data_liaoxiao/4test/22_1.h5', 'r') batch_x = H5_file['data'][:] batch_y = H5_file['label3'][:] H5_file.close() batch_x = np.transpose(batch_x, (1, 2, 0)) data_input_c[0, :, :, :, 0] = batch_x[:, :, :] # 保存或加載權重 # pre = model.predict_on_batch(data_input_c) # model.save('G:\qweqweqweqwe\model.h5') model.load_weights( filepath=
os.system('mkdir '+log_save_Path) os.system('mkdir '+model_save_Path) os.system('mkdir '+test_log_save_path) os.system('mkdir '+ver_log_save_path) # 开始训练:一下代码由main改变而来,但是不需要保存模型 if __name__ == "__main__": # prepare container:准备网络输入输出容器 暂时测试新getbatch函数,所以注释掉了 # data_input_c = np.zeros([batch_size] + data_input_shape + [1], dtype=np.float32) # net input container # label_input_c = np.zeros([batch_size] + label_shape) # 构建网络并compile # d_model_1 = vgg16_w_3d(use_bias_flag=True,classes=2) d_model = resnet_or(use_bias_flag=False,classes=2,inputshape=data_input_shape) # d_model_1 = resnext(classes=2, use_bias_flag=True) # d_model_1 = SparseNetImageNet121(classes = 2,activation='softmax',dropout_rate = 0.5) # d_model_1 = se_dense_net(nb_layers=[6, 12, 24, 16], growth_rate=32, nb_filter=64, bottleneck=True, reduction=0.0, dropout_rate=None, subsample_initial_block=True) if multi_gpu_mode: d_model = multi_gpu_model(d_model, gpus=gpu_munum) d_model.compile(optimizer=adam(lr=init_lr), loss=categorical_crossentropy, metrics=[y_t, y_pre, Acc]) # d_model.compile(optimizer=SGD(lr=init_lr, momentum=0.9), loss=categorical_crossentropy, metrics=[y_t, y_pre, Acc]) # d_model.compile(optimizer=SGD(lr=init_lr,momentum=0.9), loss='categorical_crossentropy', metrics=[y_t, y_pre, Acc]) # pause() # identify # print(d_model.summary()) # view net # pause() # identify # extra param initialization:初始化一些用来记录和显示的参数