Example: Using Backbone Replacement to Optimize Built-in Algorithms on Ascend 910 Without Modifying Code
On Ascend 910, ModelArts finds some better structures than the original ResNet-50. This example describes how to use the found structures to optimize the ResNet-50 of the built-in algorithms without modifying code.
Sample Code
The following sample code uses a built-in algorithm to train the flower dataset on the ResNet-50 network.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import argparse
import os
import json
import sys
import moxing as mox
from moxing.tensorflow.builtin_algorithms.algorithm_common import AlgorithmLego
app_url = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, os.path.dirname(__file__))
from algo_util import data_util
parser = argparse.ArgumentParser(description='')
parser.add_argument('--task_type', type=str, default=None, help='')
parser.add_argument('--train_url', type=str, default=None, help='')
def main():
args, _ = parser.parse_known_args()
print ("args", args)
flag_dict = data_util.do_preprocess()
alego = AlgorithmLego()
alego.add(args.task_type, flag_dict=flag_dict)
alego.start()
mox.file.shift("os", "mox")
with open("{}/metric.json".format(args.train_url)) as f:
metric = json.load(f)
accuracy = metric["total_metric"]["total_metric_values"]["accuracy"]
print("accuracy:%d." % accuracy)
if __name__ == "__main__":
main()
|
Compiling the Configuration File
Compile the YAML configuration file. For details, see Modifying Reporter Without Modifying Code in Code Compilation Specifications and Example: Replacing the Original ResNet-50 with a Better Network Architecture.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
general:
cpu_per_instance: 1
gpu_per_instance: 0
npu_per_instance: 1
search_space:
builtin: ResNet50
search_algorithm:
type: grid_search
reward_attr: accuracy
report_keys:
- name: accuracy
regex: (?<=accuracy:).+(?=.)
scheduler:
type: FIFOScheduler
|
Starting a Search Job
In this example, you need to prepare a dataset based on the input requirements of the built-in algorithm, upload and configure the dataset following the instructions in Example: Replacing the Original ResNet-50 with a Better Network Architecture, upload the Python script and YAML configuration file, and select the Ascend chip-powered search engine based on the section "Creating an Auto Search Job". Then start the search job on the Ascend chip.
Last Article: Example: Using Multisearch
Next Article: Model Management
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.