Exemplo n.º 1
0
def load_dialogs():
    """ Load dialogs from json file """
    global DIALOGS
    if not DIALOGS:
        with open(ros_utils.get_fullpath(__file__, 'static/dialogs.json')) as f:
            DIALOGS = json.loads(f.read())
    return DIALOGS
Exemplo n.º 2
0
    def test_segmentation_rate_on_two_frames(self):
        """ Loads images and posts the corresponding segmentation rates """
        test_images = helper.load_test_images(
            __file__, ros_utils.get_fullpath(__file__, "test.json"))

        for image in test_images:
            self.assertFalse(rospy.is_shutdown())

            rospy.loginfo("### Test image %s ###", image[helper.FILENAME])
            self.segmentation_should_find_most_of_the_objects(image)
Exemplo n.º 3
0
def load_test_images(file, test_filepath):
    """ Loads test data and images"""
    test_images = []
    with open(test_filepath) as json_data:
        file_data = json.load(json_data)

    for test in file_data["tests"]:
        test_images.append({
            IMAGE_MSG: image_utils.image_file_to_ros_msg(ros_utils.get_fullpath(file, test["imageName"])),
            FILENAME: test["imageName"],
            EXPECTED_OBJECTS: test["refData"]["objects"]
        })

    return test_images
Exemplo n.º 4
0
    def test_image_size_should_not_affect_segmentation_too_much(self):
        """ Tests image size """
        test_images = helper.load_test_images(
            __file__, ros_utils.get_fullpath(__file__, "test2.json"))

        expected_objects = test_images[0][helper.EXPECTED_OBJECTS]
        images_objects_missed = []

        for image in test_images:
            self.assertFalse(rospy.is_shutdown())
            object_found = self.get_objects_found(image)
            images_objects_missed.append(
                helper.get_missed_objects(expected_objects, object_found))

        for object_missed in images_objects_missed:
            self.assertLessEqual(
                len(object_missed), 1,
                "Too much expected objects were not detected.")

        objects_missed_from_smaller_image = images_objects_missed[0]
        for i in range(2, len(images_objects_missed)):
            self.assertGreaterEqual(objects_missed_from_smaller_image,
                                    len(images_objects_missed[i]) + 1)
Exemplo n.º 5
0
    def test_image_quality_should_not_affect_segmentation(self):
        """ Tests image quality """
        test_images = helper.load_test_images(
            __file__, ros_utils.get_fullpath(__file__, "test1.json"))

        expected_objects = test_images[0][helper.EXPECTED_OBJECTS]
        images_objects_found = []

        for image in test_images:
            self.assertFalse(rospy.is_shutdown())
            images_objects_found.append(self.get_objects_found(image))

        kinect_missed_objects = len(
            helper.get_missed_objects(expected_objects,
                                      images_objects_found[0]))
        s8_missed_objects = len(
            helper.get_missed_objects(expected_objects,
                                      images_objects_found[1]))

        self.assertAlmostEqual(kinect_missed_objects,
                               s8_missed_objects,
                               delta=1)
        self.assertLessEqual(kinect_missed_objects, 1)
        self.assertLessEqual(s8_missed_objects, 1)
Exemplo n.º 6
0
from cv_bridge import CvBridge

sys.path.append(
    os.path.join(os.path.dirname(os.path.realpath(__file__)),
                 '../../Mask_RCNN'))

import coco
import model as modellib
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
from devine_config import topicname
from ros_image_processor import ImageProcessor, ROSImageProcessingWrapper
from devine_image_processing.msg import SegmentedImage, SceneObject

# Paths
COCO_MODEL_PATH = ros_utils.get_fullpath(__file__, '../../mask_rcnn_coco.h5')
MODEL_DIR = ros_utils.get_fullpath(__file__, 'logs')

# Topics
IMAGE_TOPIC = topicname('segmentation_image')
SEGMENTATION_TOPIC = topicname('objects')

# This threshold removes objects with a lower confidence level
SEGMENTATION_THRESHOLD = 0.7


class RCNNSegmentation(ImageProcessor):
    """ RCNN segmentation wrapper of Mask_RCNN for use in guesswhat """
    class_names = [
        'BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
        'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
Exemplo n.º 7
0
import numpy as np

from guesswhat.models.guesser.guesser_network import GuesserNetwork
from guesswhat.models.qgen.qgen_lstm_network import QGenNetworkLSTM
from guesswhat.models.qgen.qgen_wrapper import QGenWrapper
from guesswhat.models.looper.basic_looper import BasicLooper
from guesswhat.data_provider.guesswhat_dataset import Game
from guesswhat.data_provider.guesswhat_tokenizer import GWTokenizer
from guesswhat.data_provider.questioner_batchifier import QuestionerBatchifier

from modelwrappers import GuesserROSWrapper, OracleROSWrapper
from devine_config import topicname
from devine_common import ros_utils
from devine_image_processing.msg import SegmentedImage, VGG16Features

EVAL_CONF_PATH = ros_utils.get_fullpath(__file__, '../../config/eval.json')
GUESS_CONF_PATH = ros_utils.get_fullpath(__file__, '../../config/guesser.json')
QGEN_CONF_PATH = ros_utils.get_fullpath(__file__, '../../config/qgen.json')
GUESS_NTW_PATH = ros_utils.get_fullpath(__file__, '../../data/guesser.ckpt')
QGEN_NTW_PATH = ros_utils.get_fullpath(__file__, '../../data/qgen.ckpt')
TOKENS_PATH = ros_utils.get_fullpath(__file__, '../../data/tokens.json')

# topics
SEGMENTATION_TOPIC = topicname('objects')
FEATURES_TOPIC = topicname('image_features')
STATUS_TOPIC = topicname('guesswhat_status')
# TODO: merge these topics to one
OBJECT_TOPIC = topicname('guess_location_image')
CATEGORY_TOPIC = topicname('guess_category')

Exemplo n.º 8
0
__email__ = "*****@*****.**"
__status__ = "Production"

import rospy
import cv2
import tensorflow as tf
from std_msgs.msg import String
from bson import json_util
from tf_pose.estimator import TfPoseEstimator
from keras.backend.tensorflow_backend import set_session
from devine_config import topicname
from devine_common import ros_utils
from ros_image_processor import ImageProcessor, ROSImageProcessingWrapper

# Originally in './models/graph/mobilenet_thin/graph_opt.pb'
MODEL_DIR = ros_utils.get_fullpath(__file__, '../../mobilenet_thin.pb')

# Topics
IMAGE_TOPIC = topicname('body_tracking_image')
PUBLISH_TOPIC = topicname('body_tracking')

class BodyTracking(ImageProcessor):
    """ Body Tracking wrapper of tf_pose for use in guesswhat """

    body_parts_names = [
        'Nose', 'Neck', 'RShoulder', 'RElbow', 'RWrist', 'LShoulder', 'LElbow', 'LWrist', 'RHip', 'RKnee',
        'RAnkle', 'LHip', 'LKnee', 'LAnkle', 'REye', 'LEye', 'REar', 'LEar', 'Background'
    ]

    def __init__(self):
        config = tf.ConfigProto(log_device_placement=False)
Exemplo n.º 9
0
__email__ = "*****@*****.**"
__status__ = "Production"

import cv2
import tensorflow as tf
import numpy as np
import rospy
from PIL import Image
from rospy.numpy_msg import numpy_msg
from tensorflow.contrib.slim.python.slim.nets import vgg
from devine_image_processing.msg import VGG16Features
from devine_config import topicname
from devine_common import ros_utils
from ros_image_processor import ImageProcessor, ROSImageProcessingWrapper

VGG16_NTW_PATH = ros_utils.get_fullpath(__file__, '../../vgg_16.ckpt')

FEATURES_TOPIC = topicname('image_features')
IMAGE_TOPIC = topicname('features_extraction_image')

IMAGE_SIZE = 224
CHANNEL_MEAN = np.array([123.68, 116.779, 103.939])


class ROSVgg16(ImageProcessor):
    """ VGG-16 wrapper for ROS """
    def __init__(self):
        self.holder = tf.placeholder(
            tf.float32, [None, IMAGE_SIZE, IMAGE_SIZE,
                         len(CHANNEL_MEAN)],
            name='image')