Ejemplo n.º 1
0
    def test_pretrained(self):
        # Load efficientdet pretrained on VOC2007
        model = EfficientDet.from_pretrained('D0-VOC', score_threshold=.6)
        print('Done loading...')
        image = io.load_image('test/data/VOC2007/JPEGImages/000002.jpg',
                              (model.config.input_size, ) * 2)
        n_image = normalize_image(image)
        n_image = tf.expand_dims(n_image, axis=0)

        classes = voc.IDX_2_LABEL

        boxes, labels, scores = model(n_image, training=False)
        labels = [classes[l] for l in labels[0]]

        im = image.numpy()
        for l, box, s in zip(labels, boxes[0].numpy(), scores[0]):
            x1, y1, x2, y2 = box.astype('int32')

            cv2.rectangle(im, (x1, y1), (x2, y2), (0, 255, 0), 2)
            cv2.putText(im, l + ' {:.2f}'.format(s), (x1, y1 - 10),
                        cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2)

        plt.imshow(im)
        plt.axis('off')
        plt.savefig('test.png')
        plt.show(block=True)
    def test_pretrained(self):
        # Load efficientdet pretrained on VOC2007
        model = EfficientDet.from_pretrained('D0-VOC', score_threshold=.3)
        print('Done loading...')
        image = io.load_image('imgs/cat-dog.jpg', model.config.input_size)
        n_image = normalize_image(image)
        n_image = tf.expand_dims(n_image, axis=0)

        classes = voc.IDX_2_LABEL

        boxes, labels, scores = model(n_image, training=False)
        labels = [classes[l] for l in labels[0]]

        colors = visualizer.colors_per_labels(labels)
        im = visualizer.draw_boxes(image,
                                   boxes[0],
                                   labels,
                                   scores[0],
                                   colors=colors)

        plt.imshow(im)
        plt.axis('off')
        plt.show(block=True)
Ejemplo n.º 3
0
from efficientdet import EfficientDet
from efficientdet.data import preprocess
from efficientdet.utils.io import load_image
from efficientdet.data.voc import IDX_2_LABEL
# import efficientdet

print(hub.__version__)
print(tf.__version__)

model_url = "https://tfhub.dev/tensorflow/efficientdet/d3/1"
# base_model = hub.KerasLayer(model_url, input_shape=(299, 299, 3))
# base_model = hub.load(model_url)
# print(base_model.summary())
"""my_model = tf.keras.applications.VGG16()
print(my_model.summary())
"""
"""hub_layer = hub.KerasLayer(model_url, output_shape=[20], input_shape=[], dtype=tf.string, trainable=True)
model = tf.keras.Sequential()
model.add(hub_layer)
model.add(tf.keras.layers.Dense(16, activation="relu", input_shape=[20]))
model.add(tf.keras.layers.Dense(1, activation="sigmoid"))
print(model.summary())"""
"""bla = tarfile.open("efficientdet-d0.tar.gz")
bla.extractall()
print(bla)
print("done")"""

model = EfficientDet.from_pretrained("D0-VOC", score_threshold=0.3)
image_size = model.config.input_size
print(image_size)
Ejemplo n.º 4
0
# In[ ]:


from efficientdet import visualizer
from efficientdet import EfficientDet
from efficientdet.data import preprocess
from efficientdet.utils.io import load_image
from efficientdet.data.voc import IDX_2_LABEL

import tensorflow as tf


# In[3]:


model = EfficientDet.from_pretrained('D0-VOC', score_threshold=.3)
image_size = model.config.input_size


# In[4]:


image = load_image('sample.jpg', image_size)
image.shape


# In[ ]:


n_image = preprocess.normalize_image(image)
n_image = tf.expand_dims(n_image, 0)