File size: 1,196 Bytes
752c636
 
 
9efc67a
752c636
 
 
 
 
 
3e96ee0
 
 
 
752c636
3e96ee0
 
 
 
 
40c8935
3e96ee0
 
 
 
 
 
 
 
 
 
 
752c636
3e96ee0
 
 
 
752c636
 
3e96ee0
752c636
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
39
40
41
42
import os
import tensorflow as tf
from tensorflow.keras import Model,layers
from face_detection.config import class_names

os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

# custom layer for reshaping last layer
class yolo_reshape(tf.keras.layers.Layer):

  def __init__(self,num_anchors,last_item, **kwargs):
    super(yolo_reshape, self).__init__(**kwargs)    
    self.last_item=last_item
    self.num_anchors=num_anchors

  def call(self,output_layer):
    shape = [tf.shape(output_layer)[k] for k in range(4)]
    return tf.reshape(output_layer,[shape[0],shape[1],shape[2],self.num_anchors,self.last_item])
  
  def compute_output_shape(self, input_shape):
    return (input_shape[0],input_shape[1],input_shape[2],self.num_anchors,self.last_item)

  
  def get_config(self):
    config = super(yolo_reshape, self).get_config()
    config.update(
        {
            "last_item": self.last_item,
            "num_anchors": self.num_anchors
        }
    )
    return config
    
  @classmethod
  def from_config(cls, config):
    return cls(**config)
  

def load_model(path):
    model=tf.keras.models.load_model(path,compile=False,custom_objects={"yolo_reshape":yolo_reshape})
    return model