set_seed(1) if __name__ == '__main__': args_opt = train_parse_args() args_opt.dataset_path = os.path.abspath(args_opt.dataset_path) config = set_config(args_opt) start = time.time() print(f"train args: {args_opt}\ncfg: {config}") #set context and device init context_device_init(config) # define network backbone_net, head_net, net = define_net(config, args_opt.is_training) dataset = create_dataset(dataset_path=args_opt.dataset_path, do_train=True, config=config) step_size = dataset.get_dataset_size() if args_opt.pretrain_ckpt: if args_opt.freeze_layer == "backbone": load_ckpt(backbone_net, args_opt.pretrain_ckpt, trainable=False) step_size = extract_features(backbone_net, args_opt.dataset_path, config) else: load_ckpt(net, args_opt.pretrain_ckpt) if step_size == 0: raise ValueError("The step_size of dataset is zero. Check if the images' count of train dataset is more \ than batch_size in config.py") # Currently, only Ascend support switch precision. switch_precision(net, mstype.float16, config)
type=str, choices=["AIR", "ONNX", "MINDIR"], default="AIR", help="file format") parser.add_argument('--platform', type=str, default="Ascend", choices=("Ascend", "GPU", "CPU"), help='run platform, only support GPU, CPU and Ascend') args = parser.parse_args() args.is_training = False args.run_distribute = False context.set_context(mode=context.GRAPH_MODE, device_target=args.platform) if args.platform == "Ascend": context.set_context(device_id=args.device_id) if __name__ == '__main__': cfg = set_config(args) set_context(cfg) _, _, net = define_net(cfg, args.is_training) load_ckpt(net, args.ckpt_file) input_shp = [args.batch_size, 3, cfg.image_height, cfg.image_width] input_array = Tensor( np.random.uniform(-1.0, 1.0, size=input_shp).astype(np.float32)) export(net, input_array, file_name=args.file_name, file_format=args.file_format)
from src.models import CrossEntropyWithLabelSmooth, define_net set_seed(1) if __name__ == '__main__': args_opt = train_parse_args() config = set_config(args_opt) start = time.time() print(f"train args: {args_opt}\ncfg: {config}") #set context and device init context_device_init(config) # define network backbone_net, head_net, net = define_net(args_opt, config) # CPU only support "incremental_learn" if args_opt.train_method == "incremental_learn": step_size = extract_features(backbone_net, args_opt.dataset_path, config) net = head_net elif args_opt.train_method in ("train", "fine_tune"): if args_opt.platform == "CPU": raise ValueError( "Currently, CPU only support \"incremental_learn\", not \"fine_tune\" or \"train\"." ) dataset = create_dataset(dataset_path=args_opt.dataset_path, do_train=True, config=config)
eval. """ from mindspore import nn from mindspore.train.model import Model from mindspore.common import dtype as mstype from src.dataset import create_dataset from src.config import set_config from src.args import eval_parse_args from src.models import define_net, load_ckpt from src.utils import switch_precision, set_context if __name__ == '__main__': args_opt = eval_parse_args() config = set_config(args_opt) backbone_net, head_net, net = define_net(config) #load the trained checkpoint file to the net for evaluation if args_opt.head_ckpt: load_ckpt(backbone_net, args_opt.pretrain_ckpt) load_ckpt(head_net, args_opt.head_ckpt) else: load_ckpt(net, args_opt.pretrain_ckpt) set_context(config) switch_precision(net, mstype.float16, config) dataset = create_dataset(dataset_path=args_opt.dataset_path, do_train=False, config=config) step_size = dataset.get_dataset_size() if step_size == 0: raise ValueError("The step_size of dataset is zero. Check if the images count of train dataset is more \