-
Notifications
You must be signed in to change notification settings - Fork 4
/
convert.py
37 lines (28 loc) · 1.05 KB
/
convert.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
36
37
from absl import app, flags, logging
from absl.flags import FLAGS
import numpy as np
from yolov3.models import YoloV3
from yolov3.utils import load_darknet_weights
import tensorflow as tf
flags.DEFINE_string('weights', './data/yolov3.wiegthts', 'path to weights file')
flags.DEFINE_string('output', './checkpoints/yolov3.tf', 'path to output')
flags.DEFINE_integer('num_classes', 80, 'number of classes in the model')
def main(_argv):
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)
yolo = YoloV3(classes=FLAGS.num_classes)
yolo.summary()
logging.info("model created")
load_darknet_weights(yolo, FLAGS.weights, False) # False for absence of yolo-TinY
logging.info("weights loaded")
img = np.random.random((1,320,320,3)).astype(np.float32)
output = yolo(img)
logging.info("sanity check passed")
yolo.save_weights(FLAGS.output)
logging.info("weights saved")
if __name__ == '__main__':
try:
app.run(main)
except SystemExit:
pass