def get_weight(file_name):
    component = UserParameters().get_component()

    if component == CLOUD:
        return gcs.get_weights(file_name)
    else:
        return UserParameters().get_base_path() + '/weights/' + str(file_name)
예제 #2
0
def factory_get_dataset_db(dataset_type):
    component = UserParameters().component
    system = UserParameters().get_system()
    if component == NODE:
        if system == 'WINDOWS':
            return PyMongoDatasetDBV2(dataset_type)
        else:
            return GcpDatasetDBV2()
    elif component == EDGE:
        return PyMongoDatasetDBV2(dataset_type)
    elif component == CLOUD:
        return GcpDatasetDBV2()
    else:
        raise Exception('Dataset DB not defined for component: ' + str(component))
 def __init__(self):
     config_parser = configparser.ConfigParser()
     config_parser.read(UserParameters().get_base_path() + CONFIG_FILE)
     self.classes = list(config_parser[E_FUSION]['CLASSES'].split(','))
     self.image_size_width = int(
         config_parser[E_FUSION]['IMAGE_SIZE_WIDTH'])
     self.image_size_height = int(
         config_parser[E_FUSION]['IMAGE_SIZE_HEIGHT'])
     self.alpha = float(config_parser[E_FUSION]['ALPHA'])
     self.boxes_per_cell = int(config_parser[E_FUSION]['BOXES_PER_CELL'])
     self.object_scale = float(config_parser[E_FUSION]['OBJECT_SCALE'])
     self.no_object_scale = float(
         config_parser[E_FUSION]['NO_OBJECT_SCALE'])
     self.class_scale = float(config_parser[E_FUSION]['CLASS_SCALE'])
     self.coord_scale = float(config_parser[E_FUSION]['COORD_SCALE'])
     self.learning_rate = float(config_parser[E_FUSION]['LEARNING_RATE'])
     self.decay_steps = int(config_parser[E_FUSION]['DECAY_STEPS'])
     self.decay_rate = float(config_parser[E_FUSION]['DECAY_RATE'])
     self.batch_size = int(config_parser[E_FUSION]['BATCH_SIZE'])
     self.epoch = int(config_parser[E_FUSION]['EPOCH'])
     self.max_iter = int(config_parser[E_FUSION]['MAX_ITER'])
     self.summary_iter = int(config_parser[E_FUSION]['SUMMARY_ITER'])
     self.save_iter = int(config_parser[E_FUSION]['SAVE_ITER'])
     self.threshold = float(config_parser[E_FUSION]['THRESHOLD'])
     self.iou_threshold = float(config_parser[E_FUSION]['IOU_THRESHOLD'])
     self.num_cameras = int(config_parser[E_FUSION]['NUM_CAMERAS'])
     self.weight_file = config_parser[E_FUSION]['WEIGHT_FILE']
     self.staircase = config_parser[E_FUSION]['STAIRCASE']
     self.gpu = float(config_parser[E_FUSION]['GPU'])
     self.output_file = config_parser[E_FUSION]['OUTPUT_FILE']
     self.grid_h = int(config_parser[E_FUSION]['GRID_H'])
     self.grid_w = int(config_parser[E_FUSION]['GRID_W'])
     self.n_anchors = config_parser[E_FUSION]['N_ANCHORS']
     self.anchors = ast.literal_eval(config_parser[E_FUSION]['ANCHORS'])
예제 #4
0
def run_camera(camera_chain, video_file_loc):
    # buffers for demo in batch
    buffer_inp = list()

    # Loop through frames
    elapsed = 0
    start = timer()
    data_collector = DataCollector()

    print('Video file to open: ' + str(video_file_loc))

    while True:
        frame_num = 0
        while frame_num < FRAME_LIMIT:
            print('Press [ESC] to quit demo')
            camera = cv2.VideoCapture(video_file_loc)
            cam_num = UserParameters().get_cam_num()

            while camera.isOpened():
                elapsed += 1
                _, frame = camera.read()
                frame_num = frame_num + 1
                if frame is None:
                    print('\nEnd of Video')
                    break
                buffer_inp.append(frame)
                # Only process and imshow when queue is full
                if elapsed % QUEUE == 0:
                    for image in buffer_inp:
                        collector_start_time = timer()
                        process_image_response = process_img_request(
                            image, cam_num, frame_num,
                            camera_chain.get_processor())
                        cv2.imshow('', process_image_response.boxed_image)
                        #cv2.imshow('', image)
                        duration = str(timer() - collector_start_time)
                        print('Processing Time: ' + duration)
                        data_collector.write(DATA_TYPE_PROCESSING_TIME,
                                             duration)
                    # Clear Buffers
                    buffer_inp = list()

                if elapsed % 5 == 0:
                    sys.stdout.write('\r')
                    fps = elapsed / (timer() - start)
                    sys.stdout.write('{0:3.3f} FPS\n'.format(fps))
                    data_collector.write(DATA_TYPE_FPS, str(fps))
                    sys.stdout.flush()
                choice = cv2.waitKey(1)
                if choice == 27:
                    break

            sys.stdout.write('\n')
            camera.release()
            data_collector.close()
            cv2.destroyAllWindows()


#run_camera()
 def __init__(self):
     config_parser = configparser.ConfigParser()
     config_parser.read(UserParameters().get_base_path() + CONFIG_FILE)
     #config_parser.read('D://Files//Box Sync//research//source code//Grit//' + CONFIG_FILE)
     self.is_cluster = config_parser[SYSTEM]['CLUSTER']
     self.is_larger_model = config_parser[SYSTEM]['USE_LARGER_MODEL']
     self.is_battery_saver = config_parser[SYSTEM]['BATTERY_SAVER']
     self.is_save_images = config_parser[SYSTEM]['SAVE_IMAGES']
     self.is_train = config_parser[SYSTEM]['TRAIN']
     self.component = config_parser[SYSTEM]['COMPONENT']
def get_image(image, predictions):
    if len(predictions) <= 0:
        return image
    else:
        if UserParameters().get_none_node_model() == 'YOLOV2':
            label_array = [
                'background',
                'aeroplane',
                'bicycle',
                'bird',
                'boat',
                'bottle',
                'bus',
                'car',
                'cat',
                'chair',
                'cow',
                'diningtable',
                'dog',
                'horse',
                'motorbike',
                'person',
                'pottedplant',
                'sheep',
                'sofa',
                'train',
                'tvmonitor',
                'unknown',
                'basketball'  # may need to remove
            ]
        else:
            label_array = [
                'tvmonitor',
                'train',
                'person',
                'boat',
                'horse',
                'cow',
                'bottle',
                'dog',
                'aeroplane',
                'car',
                'bus',
                'bicycle',
                'chair',
                'diningtable',
                'pottedplant',
                'bird',
                'cat',
                'motorbike',
                'sheep',
                'sofa',
                'background',
            ]
        return draw_boxes2(image, predictions, label_array)
 def __init__(self):
     config_parser = configparser.ConfigParser()
     config_parser.read(UserParameters().get_base_path() + CONFIG_FILE)
     self.prediction_accuracy = config_parser[THRESHOLDS][
         'PREDICTION_ACCURACY']
     self.battery_percent = config_parser[THRESHOLDS]['BATTERY_PERCENT']
     self.computation_time = config_parser[THRESHOLDS]['COMPUTATION_TIME']
     self.send_image_traffic = config_parser[THRESHOLDS][
         'SEND_IMAGE_TRAFFIC']
     self.train_size = config_parser[THRESHOLDS]['TRAIN_SIZE']
     self.train_error_rate = config_parser[THRESHOLDS]['TRAIN_ERROR_RATE']
예제 #8
0
    def process(self, request):
        component = UserParameters().get_component()
        response_code = status.ResponseStatus.SUCCESS

        if component == NODE:
            boxed_image, boxes = YoloV2Tiny().predict(request.request.image)
            request.request.set_prediction(boxes)
            response_code = status.ResponseStatus.CONTINUE
        else:
            boxed_image, boxes = get_none_node_model().predict(
                request.request.image)

        return GeneralResponse(response_code, boxed_image, boxes)
def post_to_multi_view(request):
    data = {
        'cam':
        request.cam_num,
        'frame':
        request.frame_num,
        'prediction':
        [create_box_resp_field(pred) for pred in request.predicted_box_loc]
    }

    size_of_request = asizeof.asizeof(data)
    print('Size of request: ' + str(size_of_request))

    start_time = time.time()

    resp = requests.post(str(UserParameters().get_edge_ip()) +
                         MULTI_VIEW_RELATIVE_URL,
                         headers={'Content-Type': 'application/json'},
                         data=json.dumps(data),
                         verify=False)
    status_code = resp.status_code
    size_of_resp = asizeof.asizeof(resp.content)
    total_size = str(size_of_request + size_of_resp)
    resp = resp.json()
    print('Size of response: ' + str(size_of_resp))
    print('Total transfer size: ' + total_size)

    duration = str(time.time() - start_time)
    prediction = 'Count: ' + str(len(resp['prediction'])) + ', ' + str(
        resp['prediction'])
    print('Data Transfer Time: ' + duration)
    print('Results: ' + prediction)

    data_collector = DataCollector()
    data_collector.write(DATA_TYPE_TRANSFER_SIZE, total_size)
    data_collector.write(DATA_TYPE_DATA_TRANSFER_TIME, duration)
    data_collector.write(DATA_TYPE_DETECTION, prediction)

    return NodeResponse(cc.get_status(status_code),
                        cc.get_image(request.image, resp['prediction']),
                        resp['prediction'])
예제 #10
0
    def __new__(self, *args, **kwargs):
        if self._instance is None:
            self._instance = super().__new__(self, *args, **kwargs)
            labels = DatasetDBV2(DATASET_VOC).find_label_data(LabelFindBuilder().build())
            #labels = labels + DatasetDBV2(DATASET_IMAGENET).find_label_data(LabelFindBuilder().build())
            self.label_array = [label.get_name() for label in labels]
            self.config = None
            config_loc = UserParameters().get_base_path() + '/thirdparty/kerasyolo/config.json'
            with open(config_loc) as config_buffer:
                self.config = json.load(config_buffer)

            self.model = YOLO(backend='Full Yolo',
                              input_size=self.config['model']['input_size'],
                              labels=self.label_array,
                              max_box_per_image=self.config['model']['max_box_per_image'],
                              anchors=self.config['model']['anchors'])

            weights_loc = get_weight('yolov2voc_v3.h5')
            print('Weight location: ' + str(weights_loc))
            self.model.load_weights(weights_loc)
        return self._instance
예제 #11
0
from common.userparameters import UserParameters
from config.configadapters import WINDOWS, LINUX
from endpoints import edgeendpoint
import threading
system = str(UserParameters().get_system())
if system == WINDOWS:
    from waitress import serve


def run_system_processing_speed_monitoring():
    pass  # This is in private github account


def run_network_traffic_monitoring():
    pass  # This is in private github account


def run_service():
    if system == WINDOWS:
        serve(edgeendpoint.create_app(), host='0.0.0.0', port=8080)
    elif system == LINUX:
        edgeendpoint.create_app().run(host='0.0.0.0')
    else:
        raise Exception('Invalid system: ' + str(system))


def main():
    service_thread = threading.Thread(
        name='monitor_system_processing_speed',
        target=run_system_processing_speed_monitoring)
    service_thread.start()
def post_to_single_view(request):
    return cc.send_request(
        str(UserParameters().get_edge_ip()) + SINGLE_VIEW_RELATIVE_URL,
        request)
예제 #13
0
def run_main():
    parser = argparse.ArgumentParser(description='Initial values set up.')
    parser.add_argument('-s',
                        '--system',
                        help='Operating System, either WINDOWS or LINUX',
                        required='True',
                        default=WINDOWS)
    parser.add_argument('-c',
                        '--component',
                        help='System Component, either NODE, EDGE or CLOUD',
                        required='True',
                        default=EDGE)
    parser.add_argument(
        '-m',
        '--model',
        help='Object Detection Model, either YOLOV2 or FASTERRCNN',
        required='True',
        default='YOLOV2')
    parser.add_argument('-v',
                        '--video',
                        help='Video location if exist',
                        default='NONE')
    parser.add_argument(
        '-C',
        '--camnum',
        help='Camera number of node. Applies only for Node component.',
        default='NONE')
    parser.add_argument('-nurl',
                        '--nodeurl',
                        help='IP Address of Node',
                        default='localhost')
    parser.add_argument('-eurl',
                        '--edgeurl',
                        help='IP Address of Edge',
                        default='localhost')
    parser.add_argument('-curl',
                        '--cloudurl',
                        help='IP Address of Cloud',
                        default='localhost')
    arguments = parser.parse_args(sys.argv[1:])
    system = arguments.system
    base_path = get_base_path()
    component = arguments.component
    model = arguments.model
    video_file_loc = arguments.video
    cam_num = arguments.camnum
    url = get_urls(component,
                   [arguments.nodeurl, arguments.edgeurl, arguments.cloudurl])
    user_parameters = UserParameters(system, base_path, component, model,
                                     video_file_loc, cam_num, url)
    app_component = user_parameters.get_component()
    if app_component == NODE:
        import app.mainnode as node
        node.main()
    elif app_component == EDGE:
        import app.mainedge as edge
        edge.main()
    elif app_component == CLOUD:
        import app.maincloud as cloud
        cloud.main()
    else:
        raise Exception('Application not set up for component: ' +
                        str(app_component))
예제 #14
0
def get_none_node_model():
    model = UserParameters().get_none_node_model()
    if model == MODEL_YOLOV2:
        return YoloV2Full()
    elif model == MODEL_FASTERRCNN:
        return FasterRcnn()
import pickle
import requests
import time

from clients.generalresponse import GeneralResponse
from clients.responsestatus import ResponseStatus
from common.data_collector import DataCollector, DATA_TYPE_DATA_TRANSFER_TIME, DATA_TYPE_TRANSFER_SIZE, DATA_TYPE_DETECTION, DATA_TYPE_COMPUTING_TIME
from common.userparameters import UserParameters
from thirdparty.kerasyolo.utils import draw_boxes2

PICKLED_TEMP_LOC = UserParameters().get_base_path(
) + '\\clients\\temp\\preprocessimage.pkl'
SINGLE_VIEW_RELATIVE_URL = "/process/image/singleview"
MULTI_VIEW_RELATIVE_URL = "/process/image/multiview"
MODEL_WEIGHT_UPDATE_SERVICE_URL = ""


def get_status(endpoint_status):
    return ResponseStatus.SUCCESS


def get_image(image, predictions):
    if len(predictions) <= 0:
        return image
    else:
        if UserParameters().get_none_node_model() == 'YOLOV2':
            label_array = [
                'background',
                'aeroplane',
                'bicycle',
                'bird',
 def __init__(self):
     config_parser = configparser.ConfigParser()
     config_parser.read(UserParameters().get_base_path() + CONFIG_FILE)
     self.model = config_parser[MODEL_CONFIG]['MODEL']