def initialize_inferance(self):
     self.detection_model = ObjectDetector(self.following_model_path)
     collision_model = torchvision.models.resnet18(pretrained=False)
     collision_model.fc = torch.nn.Linear(512, 2)
     collision_model.load_state_dict(torch.load(self.avoidance_model_path))
     collision_model = collision_model.to(self.device)
     self.collision_model = collision_model.eval().half()
Esempio n. 2
0
 def __init__(self):
     from jetbot import ObjectDetector
     following_model_path = "/home/jetbot/catkin_ws/src/sim_nank/weights/ssd_mobilenet_v2_coco.engine"
     self.detection_model = ObjectDetector(following_model_path)
     print("detection object make success")
     self.cap = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER)
     self.target_label = 1
     self.display = True
Esempio n. 3
0
        robot.forward(float(speed_widget.value))

    # otherwsie steer towards target
    else:
        # move robot forward and steer proportional target's x-distance from center
        center = detection_center(det)
        robot.set_motors(
            float(speed_widget.value + turn_gain_widget.value * center[0]),
            float(speed_widget.value - turn_gain_widget.value * center[0]))

    # update image widget
    image_widget.value = bgr8_to_jpeg(image)


model = ObjectDetector(
    '/home/dewald/projects/frameworks/nvidia/deepstream_sdk_v4.0.2_jetson/samples/models/SSD-Mobilenet-v2/ssd_mobilenet_v2_coco.engine'
)
camera = Camera.instance(width=300, height=300)
detections = model(camera.value)
print(detections)

collision_model = torchvision.models.alexnet(pretrained=False)
collision_model.classifier[6] = torch.nn.Linear(
    collision_model.classifier[6].in_features, 2)
collision_model.load_state_dict(
    torch.load('/home/dewald/projects/jetbot/jetbot/best_model.pth'))
device = torch.device('cuda')
collision_model = collision_model.to(device)
mean = 255.0 * np.array([0.485, 0.456, 0.406])
stdev = 255.0 * np.array([0.229, 0.224, 0.225])
normalize = torchvision.transforms.Normalize(mean, stdev)
Esempio n. 4
0
#!/usr/bin/env python3

import cv2
from jetbot import ObjectDetector
import os
import numpy as np
import time
from flask import Flask, render_template, Response
from importlib import import_module
from categories import *
import robot

robot = Robot()

model = ObjectDetector('ssd_mobilenet_v2_coco.engine')

camera = cv2.VideoCapture(0)
app = Flask(__name__)

start = 0
isObject = False
isMoving = False
width = 300
height = 300

def detection_center(detection):
    """Computes the center x, y coordinates of the object"""
    bbox = detection['bbox']
    center_x = (bbox[0] + bbox[2]) / 2.0 - 0.5
    center_y = (bbox[1] + bbox[3]) / 2.0 - 0.5
    return (center_x, center_y)
Esempio n. 5
0
        csv_path = os.path.join(self.directory, self.filename + '.csv')
        with open(csv_path, 'a') as outcsv:
            writer = csv.writer(outcsv)
            writer.writerows(self.tf_list)
            outcsv.close()


def save_image(image, filename, tf_list):
    global image_dir, cat_count
    background = AsyncWrite(image_dir, filename, image, tf_list)
    background.start()


logger.info('loading catbot.engine')
model = ObjectDetector('catbot.engine')

# setup models
collision_model = torchvision.models.alexnet(pretrained=False)
collision_model.classifier[6] = torch.nn.Linear(
    collision_model.classifier[6].in_features, 2)
logger.info('load collision model')
collision_model.load_state_dict(torch.load('best_model.pth'))
logger.info('done loading')
device = torch.device('cuda')
collision_model = collision_model.to(device)

mean = 255.0 * np.array([0.485, 0.456, 0.406])
stdev = 255.0 * np.array([0.229, 0.224, 0.225])

normalize = torchvision.transforms.Normalize(mean, stdev)
Esempio n. 6
0
#!/usr/bin/env python3

import time
from jetbot import ObjectDetector
following_model_path = "/home/jetbot/catkin_ws/src/sim_nank/weights/ssd_mobilenet_v2_coco.engine"
detection_model = ObjectDetector(following_model_path)
print('object make success {}'.format(detection_model))
time.sleep(5)
'''
class Controller:

    def __init__(self):
        from jetbot import ObjectDetector
        following_model_path = "/home/jetbot/catkin_ws/src/sim_nank/weights/ssd_mobilenet_v2_coco.engine"
        self.detection_model = ObjectDetector(following_model_path)   

if __name__ == '__main__':
    oc = Controller()
'''
Esempio n. 7
0
    os.makedirs(blocked_dir)
except FileExistsError:
    print('Directories not created because they already exist')
free_count = len(os.listdir(free_dir))
blocked_count = len(os.listdir(blocked_dir))
print("Free    Count : ", free_count)
print("Blocked Count : ", blocked_count)

# Camera
width = 300
height = 300
camera = Camera(width=width, height=height, rotate=False)

# SSD Object detector
print("Loading SSD Object Detector")
model = ObjectDetector('models/object_detect/ssd_mobilenet_v2_coco.engine')

# Collision Detector
print("Loading Collision Model")
collision_model = torchvision.models.alexnet(pretrained=False)
collision_model.classifier[6] = torch.nn.Linear(
    collision_model.classifier[6].in_features, 2)
collision_model.load_state_dict(
    torch.load('models/classification/best_model.pth'))
device = torch.device('cuda')
collision_model = collision_model.to(device)
mean = 255.0 * np.array([0.485, 0.456, 0.406])
stdev = 255.0 * np.array([0.229, 0.224, 0.225])
normalize = torchvision.transforms.Normalize(mean, stdev)
check_time_blocked = time.time()
check_time_free = time.time()