parser.add_argument('--learning_rate', type=float, default=1e-4, help='learning rate') parser.add_argument('--batch_size', type=int, default=8, help='batch_size') parser.add_argument( '--kf_optimizer', type=str, default='Sync_avg', help= 'kung fu parallel optimizor,available options: Sync_sgd, Sync_avg, Pair_avg' ) args = parser.parse_args() #config model Config.set_model_name(args.model_name) Config.set_model_type(Config.MODEL[args.model_type]) Config.set_model_backbone(Config.BACKBONE[args.model_backbone]) #config train Config.set_train_type(Config.TRAIN[args.train_type]) Config.set_learning_rate(args.learning_rate) Config.set_batch_size(args.batch_size) Config.set_kungfu_option(Config.KUNGFU[args.kf_optimizer]) #config dataset Config.set_dataset_type(Config.DATA[args.dataset_type]) Config.set_dataset_path(args.dataset_path) #train config = Config.get_config() model = Model.get_model(config) train = Model.get_train(config)
) parser.add_argument('--eval_num', type=int, default=10000, help='number of evaluation') parser.add_argument('--vis_num', type=int, default=60, help='number of visible evaluation') parser.add_argument('--multiscale', type=bool, default=False, help='enable multiscale_search') args = parser.parse_args() Config.set_model_name(args.model_name) Config.set_model_type(Config.MODEL[args.model_type]) Config.set_model_backbone(Config.BACKBONE[args.model_backbone]) Config.set_dataset_type(Config.DATA[args.dataset_type]) Config.set_dataset_path(args.dataset_path) Config.set_dataset_version(args.dataset_version) config = Config.get_config() model = Model.get_model(config) evaluate = Model.get_evaluate(config) dataset = Dataset.get_dataset(config) evaluate(model, dataset, vis_num=args.vis_num, total_eval_num=args.eval_num,
parser.add_argument('--train_type', type=str, default="Single_train", help='train type, available options: Single_train, Parallel_train') parser.add_argument('--kf_optimizer', type=str, default='Sma', help='kung fu parallel optimizor,available options: Sync_sgd, Async_sgd, Sma') parser.add_argument("--output_dir", type=str, default="save_dir", help="which dir to output the exported pb model") args=parser.parse_args() Config.set_model_name(args.model_name) Config.set_model_type(Config.MODEL[args.model_type]) Config.set_model_backbone(Config.BACKBONE[args.model_backbone]) config=Config.get_config() export_model=Model.get_model(config) input_path=f"{config.model.model_dir}/newest_model.npz" output_dir=f"{args.output_dir}/{config.model.model_name}" output_path=f"{output_dir}/frozen_{config.model.model_name}.pb" print(f"exporting model {config.model.model_name} from {input_path}...") if(not os.path.exists(output_dir)): print("creating output_dir...") os.mkdir(output_dir) if(not os.path.exists(input_path)): print("input model file doesn't exist!") print("conversion aborted!")
parser.add_argument('--log_interval', type=int, default=None, help='log frequency, None stands for using default value') parser.add_argument("--vis_interval", type=int, default=None, help="visualize frequency, None stands for using default value") parser.add_argument('--save_interval', type=int, default=None, help='log frequency, None stands for using default value') args=parser.parse_args() #config model Config.set_model_name(args.model_name) Config.set_model_type(Config.MODEL[args.model_type]) Config.set_model_backbone(Config.BACKBONE[args.model_backbone]) #config train Config.set_train_type(Config.TRAIN[args.train_type]) Config.set_optim_type(Config.OPTIM[args.optim_type]) Config.set_kungfu_option(Config.KUNGFU[args.kf_optimizer]) Config.set_log_interval(args.log_interval) Config.set_vis_interval(args.vis_interval) Config.set_save_interval(args.save_interval) #config dataset Config.set_official_dataset(args.use_official_dataset) Config.set_dataset_type(Config.DATA[args.dataset_type]) Config.set_dataset_path(args.dataset_path) Config.set_dataset_version(args.dataset_version) #sample add user data to train
type=str, default="Openpose", help="human pose estimation model type, available options: Openpose, LightweightOpenpose ,MobilenetThinOpenpose, PoseProposal") parser.add_argument("--dataset_type", type=str, default="MSCOCO", help="dataset name,to determine which dataset to use, available options: MSCOCO, MPII ") parser.add_argument("--dataset_path", type=str, default="/data/", help="dataset path,to determine the path to load the dataset") parser.add_argument('--train_type', type=str, default="Single_train", help='train type, available options: Single_train, Parallel_train') args = parser.parse_args() # config model Config.set_model_type(Config.MODEL[args.model_type]) # config train type Config.set_train_type(Config.TRAIN[args.train_type]) # config dataset Config.set_dataset_type(Config.DATA[args.dataset_type]) Config.set_dataset_path(args.dataset_path) config = Config.get_config() dataset = Dataset.get_dataset(config) train_dataset = dataset.save_train_tfrecord_dataset() Path("../data").mkdir(parents=True, exist_ok=True) shutil.move('coco_pose_data.tfrecord', '../data/')
import cv2 import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from hyperpose import Config,Model,Dataset from hyperpose.Dataset import imread_rgb_float,imwrite_rgb_float Config.set_model_name("openpose") Config.set_model_type(Config.MODEL.Openpose) config=Config.get_config() #get and load model model=Model.get_model(config) weight_path=f"{config.model.model_dir}/newest_model.npz" model.load_weights(weight_path) #infer on single image ori_image=cv2.cvtColor(cv2.imread("./sample.jpg"),cv2.COLOR_BGR2RGB) input_image=ori_image.astype(np.float32)/255.0 if(model.data_format=="channels_first"): input_image=np.transpose(input_image,[2,0,1]) img_c,img_h,img_w=input_image.shape conf_map,paf_map=model.infer(input_image[np.newaxis,:,:,:]) #get visualize function, which is able to get visualized part and limb heatmap image from inferred heatmaps visualize=Model.get_visualize(Config.MODEL.Openpose) vis_parts_heatmap,vis_limbs_heatmap=visualize(input_image,conf_map[0],paf_map[0],save_tofile=False,) #get postprocess function, which is able to get humans that contains assembled detected parts from inferred heatmaps postprocess=Model.get_postprocess(Config.MODEL.Openpose)
import cv2 import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from hyperpose import Config, Model, Dataset from hyperpose.Dataset import imread_rgb_float, imwrite_rgb_float Config.set_model_name("new_opps") Config.set_model_type(Config.MODEL.Openpose) config = Config.get_config() #get and load model model = Model.get_model(config) weight_path = f"{config.model.model_dir}/newest_model.npz" model.load_weights(weight_path) #infer on single image ori_image = cv2.cvtColor(cv2.imread("./sample.jpeg"), cv2.COLOR_BGR2RGB) input_image = ori_image.astype(np.float32) / 255.0 if (model.data_format == "channels_first"): input_image = np.transpose(input_image, [2, 0, 1]) img_c, img_h, img_w = input_image.shape conf_map, paf_map = model.infer(input_image[np.newaxis, :, :, :]) #get visualize function, which is able to get visualized part and limb heatmap image from inferred heatmaps visualize = Model.get_visualize(Config.MODEL.Openpose) vis_parts_heatmap, vis_limbs_heatmap = visualize(input_image, conf_map[0], paf_map[0], save_tofile=False)
type=str, default="Default", help= "model backbone, available options: Mobilenet, Vggtiny, Vgg19, Resnet18, Resnet50" ) parser.add_argument( "--model_name", type=str, default="default_name", help="model name,to distinguish model and determine model dir") parser.add_argument( "--dataset_path", type=str, default="./data", help="dataset path,to determine the path to load the dataset") args = parser.parse_args() #config model Config.set_model_name(args.model_name) Config.set_model_type(Config.MODEL[args.model_type]) Config.set_model_backbone(Config.BACKBONE[args.model_backbone]) Config.set_pretrain(True) #config dataset Config.set_pretrain_dataset_path(args.dataset_path) config = Config.get_config() #train model = Model.get_model(config) pretrain = Model.get_pretrain(config) dataset = Dataset.get_pretrain_dataset(config) pretrain(model, dataset)
import pathlib import tensorflow as tf from functools import partial from hyperpose import Config,Model,Dataset #load model weights from hyperpose Config.set_model_name("new_pifpaf") Config.set_model_type(Config.MODEL.Pifpaf) Config.set_dataset_type(Config.DATA.MSCOCO) config=Config.get_config() model=Model.get_model(config) model.load_weights(f"{config.model.model_dir}/newest_model.npz") model.eval() #construct representative dataset used for quantization(here using the first 100 validate images) scale_image_func=partial(Model.common.scale_image,hin=model.hin,win=model.win,scale_rate=0.95) def decode_image(image_file,image_id): image = tf.io.read_file(image_file) image = tf.image.decode_jpeg(image, channels=3) # get RGB with 0~1 image = tf.image.convert_image_dtype(image, dtype=tf.float32) scaled_image,pad = tf.py_function(scale_image_func,[image],[tf.float32,tf.float32]) return scaled_image dataset=Dataset.get_dataset(config) val_dataset=dataset.get_eval_dataset() rep_dataset=val_dataset.enumerate() rep_dataset=rep_dataset.filter(lambda i,image_data : i<=100) rep_dataset=rep_dataset.map(lambda i,image_data: image_data) rep_dataset=rep_dataset.map(decode_image).batch(1) print(f"test rep_dataset:{rep_dataset}") #covert to tf-lite using int8-only quantization input_signature=tf.TensorSpec(shape=(None,3,None,None)) converter=tf.lite.TFLiteConverter.from_concrete_functions([model.infer.get_concrete_function(x=input_signature)])