MCPcopy Index your code
hub / github.com/cloud-annotations/cloud-annotations / get_anchors

Function get_anchors

scripts/build_decoder.py:8–28  ·  view source on GitHub ↗

Computes the list of anchor boxes by sending a fake image through the graph. Outputs an array of size (4, num_anchors) where each element is an anchor box given as [ycenter, xcenter, height, width] in normalized coordinates.

(graph)

Source from the content-addressed store, hash-verified

6from coremltools.models import neural_network
7
8def get_anchors(graph):
9 """
10 Computes the list of anchor boxes by sending a fake image through the graph.
11 Outputs an array of size (4, num_anchors) where each element is an anchor box
12 given as [ycenter, xcenter, height, width] in normalized coordinates.
13 """
14 anchors_tensor = "Concatenate/concat:0"
15 with graph.as_default():
16 with tf.Session(graph=graph) as sess:
17 image_tensor = graph.get_tensor_by_name("image_tensor:0")
18 box_corners_tensor = graph.get_tensor_by_name(anchors_tensor)
19 box_corners = sess.run(box_corners_tensor, feed_dict={image_tensor: np.zeros((1, 300, 300, 3))})
20
21 # The TensorFlow graph gives each anchor box as [ymin, xmin, ymax, xmax].
22 # Convert these min/max values to a center coordinate, width and height.
23 ymin, xmin, ymax, xmax = np.transpose(box_corners)
24 width = xmax - xmin
25 height = ymax - ymin
26 ycenter = ymin + height / 2.
27 xcenter = xmin + width / 2.
28 return np.stack([ycenter, xcenter, height, width])
29
30
31def build_decoder(graph, num_classes, num_anchors):

Callers 1

build_decoderFunction · 0.85

Calls 1

runMethod · 0.80

Tested by

no test coverage detected