<commit_before>#!/usr/bin/env python

# Make sure these 2 lines are in your ~/.bashrc:

# export PYTHONPATH="/home/USER/py-faster-rcnn/lib:/home/USER/py-faster-rcnn/caffe-fast-rcnn/python:${PYTHONPATH}"
# export DRV=/home/USER/catkin_ws/src/drv_package

# Change 'USER' according to your environment

# Author: <NAME>
# 2017.9.6

# --------------------------------------------------------

import os
from fast_rcnn.config import cfg
from fast_rcnn.test import im_detect
from fast_rcnn.nms_wrapper import nms
import numpy as np
import caffe

CLASSES = ('__background__',
           'aeroplane', 'bicycle', 'bird', 'boat',
           'bottle', 'bus', 'car', 'cat', 'chair',
           'cow', 'table', 'dog', 'horse',
           'motorbike', 'person', 'plant',
           'sheep', 'sofa', 'train', 'tv')


def process(im):
    result = []

    cfg.TEST.HAS_RPN = True  # Use RPN for proposals
    if "DRV" not in os.environ:
        print "Can't find environment variable DRV."
        return result

    dir_prefix = os.environ['DRV'] + '/supplements/object_recognize/'
    prototxt = dir_prefix + 'faster_rcnn_test.pt'
    caffemodel = dir_prefix + 'VGG16_faster_rcnn_final.caffemodel'

    if os.path.isfile(prototxt) and os.path.isfile(caffemodel):
        print 'Found Caffe prototxt and model.'
    else:
        print 'Caffe prototxt or model not found!'
        return result

    use_gpu = True
    if use_gpu:
        caffe.set_mode_gpu()
        caffe.set_device(0)
        cfg.GPU_ID = 0
    else:
        caffe.set_mode_cpu()
    net = caffe.Net(prototxt, caffemodel, caffe.TEST)

    scores, boxes = im_detect(net, im)

    conf_thresh = 0.8
    nms_thresh = 0.3

    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, nms_thresh)
        dets = dets[keep, :]

        inds = np.where(dets[:, -1] >= conf_thresh)[0]
<commit_msg>global defination of net<commit_after>#!/usr/bin/env python

# Make sure these 2 lines are in your ~/.bashrc:

# export PYTHONPATH="/home/USER/py-faster-rcnn/lib:/home/USER/py-faster-rcnn/caffe-fast-rcnn/python:${PYTHONPATH}"
# export DRV=/home/USER/catkin_ws/src/drv_package

# Change 'USER' according to your environment

# Author: <NAME>
# 2017.9.6

# --------------------------------------------------------

import os
from fast_rcnn.config import cfg
from fast_rcnn.test import im_detect
from fast_rcnn.nms_wrapper import nms
import numpy as np
import caffe

CLASSES = ('__background__',
           'aeroplane', 'bicycle', 'bird', 'boat',
           'bottle', 'bus', 'car', 'cat', 'chair',
           'cow', 'table', 'dog', 'horse',
           'motorbike', 'person', 'plant',
           'sheep', 'sofa', 'train', 'tv')

dir_prefix = os.environ['DRV'] + '/supplements/object_recognize/'
prototxt = dir_prefix + 'faster_rcnn_test.pt'
caffemodel = dir_prefix + 'VGG16_faster_rcnn_final.caffemodel'

use_gpu = True
if use_gpu:
    caffe.set_mode_gpu()
    caffe.set_device(0)
    cfg.GPU_ID = 0
else:
    caffe.set_mode_cpu()
net = caffe.Net(prototxt, caffemodel, caffe.TEST)


def process(im):
    result = []

    cfg.TEST.HAS_RPN = True  # Use RPN for proposals
    if "DRV" not in os.environ:
        print "Can't find environment variable DRV."
        return result

    if os.path.isfile(prototxt) and os.path.isfile(caffemodel):
        print 'Found Caffe prototxt and model.'
    else:
        print 'Caffe prototxt or model not found!'
        return result

    global net
    scores, boxes = im_detect(net, im)

    conf_thresh = 0.8
    nms_thresh = 0.3

    for cls_ind, cls in enumerate(CLASSES[1:]):
        cls_ind += 1  # because we skipped background
        cls_boxes = boxes[:, 4 * cls_ind:4 * (cls_ind + 1)]
        cls_scores = scores[:, cls_ind]
        dets = np.hstack((cls_boxes, cls_scores[:, np.newaxis])).astype(np.float32)
        keep = nms(dets, nms_thresh)
        dets = dets[keep, :]

        inds = np.where(dets[:, -1] >= conf_thresh)[0]

{'fraction_non_alphanumeric': 0.15771812080536912, 'fraction_numerical': 0.011505273250239693, 'mean_word_length': 2.6350174216027873, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7226653', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1481, 'n_words': 349}