def get_model(name, in_shape, n_classes, backend='resnet34'): if name == 'fpn': return FPN(backbone_name=backend, input_shape=in_shape, classes=n_classes, encoder_weights=None) if name == 'unet': return Unet(backbone_name=backend, input_shape=in_shape, classes=n_classes, encoder_weights=None) if name == 'pspnet': return PSPNet50(input_shape=in_shape, n_labels=n_classes) if name == 'deeplab': return Deeplabv3(input_shape=in_shape, classes=n_classes, weights=None) if name == 'biard': return biard_net(in_shape=in_shape, n_classes=n_classes) raise ValueError("Unknown model name")
# summarize history for loss matplotlib.pyplot.subplot(212) matplotlib.pyplot.plot(history.history['loss']) matplotlib.pyplot.plot(history.history['val_loss']) matplotlib.pyplot.title('model loss') matplotlib.pyplot.ylabel('loss') matplotlib.pyplot.xlabel('epoch') matplotlib.pyplot.legend(['train', 'test'], loc='upper left') fig.savefig('depth.png', dpi=fig.dpi) # Load dataset pspnet_ini = PSPNet50(nb_classes=150, input_shape=(640, 480), weights='pspnet50_ade20k') pspnet_ini.model.layers.pop() layer_lambda = pspnet_ini.model.layers.pop() pspnet_ini.model.layers.pop() print(layer_lambda.get_config()) ''' layer_lambda = pspnet_ini.model.layers.pop() layer_lambda.get_config() ''' tf_resize = Input(shape=(640, 480)) kernel_size = (1, 1) new_layer = Conv2D(256, (1, 1), strides=(1, 1),
model = basename(dirname(args.checkpoint)) version = basename(args.checkpoint).split('-')[0] root_result = "predictions/{}/{}/{}".format(model, version, args.scale) print "Outputting to ", root_result root_mask = os.path.join(root_result, 'category_mask') root_prob = os.path.join(root_result, 'prob_mask') root_maxprob = os.path.join(root_result, 'max_prob') root_allprob = os.path.join(root_result, 'all_prob') sess = tf.Session() K.set_session(sess) with sess.as_default(): print(args) pspnet = PSPNet50(checkpoint=args.checkpoint) for im in im_list: print im fn_maxprob = os.path.join(root_maxprob, im.replace('.jpg', '.h5')) fn_mask = os.path.join(root_mask, im.replace('.jpg', '.png')) fn_prob = os.path.join(root_prob, im) fn_allprob = os.path.join(root_allprob, im.replace('.jpg', '.h5')) if os.path.exists(fn_allprob): print "Already done." continue # make paths if not exist if not os.path.exists(dirname(fn_maxprob)):
elif args.scale == "medium": maxside = 1024 elif args.scale == "big": maxside = 2048 else: maxside = None project = "ade20k" config = utils.get_config(project) im_list = utils.open_im_list(config["im_list"]) datasource = DataSource(config) data_generator = DataGenerator(im_list, datasource, maxside=maxside) # Load checkpoint checkpoint_dir = join("weights", "checkpoints", args.name) if not isdir(checkpoint_dir): makedirs(checkpoint_dir) checkpoint, epoch = (None, 0) if args.resume: checkpoint, epoch = utils.get_latest_checkpoint(checkpoint_dir) sess = tf.Session() K.set_session(sess) with sess.as_default(): print(args) pspnet = PSPNet50(activation=args.activation, checkpoint=checkpoint) train(pspnet, data_generator, checkpoint_dir, initial_epoch=epoch)
# EVALUATION_SCALES = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] # must be all floats! # EVALUATION_SCALES = [0.15, 0.25, 0.5] # must be all floats! sliding = False flip = False from ade20k_labels import labels id = {label.id for label in labels if label.name == 'ceiling'} #todo get label and idddddd img = misc.imread('PSPNet-Keras-tensorflow-master/example_images/ade20k2.jpg') #create the neural network pspnet = PSPNet50(nb_classes=150, input_shape=(473, 473), weights='pspnet50_ade20k') #Run over input data class_scores = predict_multi_scale(img, pspnet, EVALUATION_SCALES, sliding, flip) print("Writing results...") class_image = np.argmax(class_scores, axis=2) #Get best classes (highest score!!) pm = np.max(class_scores, axis=2) colored_class_image = utils.color_class_image(class_image, 'ade20k') # colored_class_image is [0.0-1.0] img is [0-255] alpha_blended = 0.5 * colored_class_image + 0.5 * img