else: init = "/Users/salvatorecapuozzo/Desktop/" if mode == 0: #model = fcn_32(n_classes=38 , input_height=224, input_width=320 ) # model = vgg_unet(n_classes=38 , input_height=416, input_width=608 ) #model = vgg_unet(n_classes=38 , input_height=416, input_width=608 ) if trainingFromInit: #model = pspnet_50_slim( n_classes=38 ) # accuracy: 0.5348 10 epochs #model = pspnet_50_ADE_20K_SUNRGB() #model = convertToSunRgb(model) #print(model.summary()) #prun_schedule = PolynomialDecay(initial_sparsity=0.0, final_sparsity=0.5,begin_step=2000,end_step=4000) #model = prune_low_magnitude(model, pruning_schedule=prun_schedule) model = pspnet_50(n_classes=38) pretrained_model = pspnet_50_ADE_20K() tf.keras.utils.plot_model( model, to_file=init + "pspnet_50.png", show_shapes=True, show_layer_names=True, rankdir="TB", expand_nested=False, dpi=96, ) tf.keras.utils.plot_model( pretrained_model, to_file=init + "pspnet_50_ade_20k.png", show_shapes=True,
import os #os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" #os.environ["CUDA_VISIBLE_DEVICES"] = "" from keras_segmentation.models.model_utils import transfer_weights from keras_segmentation.pretrained import pspnet_50_ADE_20K from keras_segmentation.models.pspnet import pspnet_50 pretrained_model = pspnet_50_ADE_20K() keji_model1 = pspnet_50(n_classes=150) transfer_weights( pretrained_model, keji_model1) # transfer weights from pre-trained model to your model keji_model1.train(train_images="../VGdata/images_prepped_train_png/", train_annotations="../VGdata/annotations_prepped_train_png/", checkpoints_path="./keji1check", epochs=5)
gc.collect() #rifare training con data augmentation, provare altre reti, transfer learning, fare valutazione gpu_devices = tf.config.experimental.list_physical_devices('GPU') for device in gpu_devices: tf.config.experimental.set_memory_growth(device, True) print(f"[INFO] Building the model..") #model = vgg_unet(n_classes=2 , input_height=512, input_width=512 ) pretrained_model = pspnet_50_ADE_20K() #model = pspnet_50( n_classes=2 ) #new model model = pspnet_50( n_classes=2 ) #new model transfer_weights( pretrained_model , model ) # transfer weights from pre-trained model to your model print(f"[INFO] Training the model..") model.train( train_images = r"D:\FISICA MEDICA\radiomics_eco\Dataset_BUSI_with_GT\segnet\images_train", train_annotations = r"D:\FISICA MEDICA\radiomics_eco\Dataset_BUSI_with_GT\segnet\masks_train", checkpoints_path =r"C:\Users\matte\PycharmProjects\ecographic_breast_nn\segnet\checkpoints\psp_unet", epochs=5,batch_size=1) print(f"[INFO] Running predictions") pdr=model.predict_multiple( inp_dir=r"D:\FISICA MEDICA\radiomics_eco\Dataset_BUSI_with_GT\segnet\images_val",
from imgaug import augmenters as iaa import imageio import numpy as np import datetime import imutils from skimage import measure, color from sklearn.decomposition import PCA from keras_segmentation.train import find_latest_checkpoint from keras_segmentation.models.model_utils import transfer_weights from keras_segmentation.pretrained import pspnet_50_ADE_20K from keras_segmentation.models.pspnet import pspnet_50 #,resnet50_pspnet #from cv2 import imresize # In[model]: new_model = pspnet_50(n_classes=2, input_height=473, input_width=473) file_model = 'new_model.299' #file_model = 'new_model_val.50' new_model.load_weights(file_model) # In[val 测试集(不用先增强,直接拆分)]: ### 原始图像和分割的路径 image_dir = r"dataset\val" # ## 切分块后保存图像和分割的路径 image_block_dir = r"dataset\block_val" image_predict_dir = r"dataset\val_predict" # In[proc]: # 指定子块的宽和高
from keras_segmentation.models.model_utils import transfer_weights from keras_segmentation.pretrained import pspnet_50_ADE_20K from keras_segmentation.models.pspnet import pspnet_50 from tensorflow.compat.v1 import InteractiveSession from tensorflow.compat.v1 import ConfigProto config = ConfigProto() config.gpu_options.allow_growth = True session = InteractiveSession(config=config) pretrained_model = pspnet_50_ADE_20K() new_model = pspnet_50(n_classes=2) transfer_weights( pretrained_model, new_model) # transfer weights from pre-trained model to your model new_model.train(train_images="/home/klz/food_training_images/", train_annotations="/home/klz/food_training_annotations/", checkpoints_path="/home/klz/checkpoints/vgg_unet_1", epochs=5)