-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
38 lines (32 loc) · 865 Bytes
/
train.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
38
import tensorflow as tf
import keras_cv
images = tf.ones(shape=(1, 512, 512, 3))
labels = {
"boxes": tf.constant([
[
[0, 0, 100, 100],
[100, 100, 200, 200],
[300, 300, 100, 100],
]
], dtype=tf.float32),
"classes": tf.constant([[1, 1, 1]], dtype=tf.int64),
}
# Create the model with mobilenet backbone
model = keras_cv.models.YOLOV8Detector.from_preset(
num_classes=20,
bounding_box_format="xywh",
preset="mobilenet_v3_large_imagenet",
load_weights=True,
)
# Evaluate model without box decoding and NMS
model(images)
# Prediction with box decoding and NMS
model.predict(images)
# Train model
model.compile(
classification_loss='binary_crossentropy',
box_loss='ciou',
optimizer=tf.optimizers.SGD(global_clipnorm=10.0),
jit_compile=False,
)
model.fit(images, labels)