forked from analogdevicesinc/ai8x-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_qat_yaml.py
35 lines (29 loc) · 1 KB
/
parse_qat_yaml.py
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
32
33
34
35
###################################################################################################
#
# Copyright (C) Maxim Integrated Products, Inc. All Rights Reserved.
#
# Maxim Integrated Products, Inc. Default Copyright Notice:
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
#
###################################################################################################
"""
Parses YAML file used to define Quantization Aware Training
"""
import yaml
def parse(yaml_file):
"""
Parses `yaml_file` that defines the QAT policy
"""
policy = None
with open(yaml_file, 'r') as stream:
try:
policy = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
print(policy)
if policy:
if 'start_epoch' not in policy:
assert False, '`start_epoch` must be defined in QAT policy'
if 'weight_bits' not in policy:
assert False, '`weight_bits` must be defined in QAT policy'
return policy