Skip to content

Commit

Permalink
standalong version (tensorflow files added)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hollyqui committed Jun 30, 2019
1 parent ec31b14 commit 585f217
Show file tree
Hide file tree
Showing 23 changed files with 1,610 additions and 31 deletions.
File renamed without changes.
8 changes: 0 additions & 8 deletions TF_object_detection/Drone_Net_Test.py → Drone_Net_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ def run(self):
self.process.set_rotation(0)
self.process.set_tilt(0)

# # Display output
# cv2.imshow('object detection', img)
#
# if cv2.waitKey(10) & 0xFF == ord('q'):
# cv2.destroyAllWindows()
# break


def compute_boxes(self, coordinates):
coordinates = np.array(coordinates)
if (not coordinates.sum() == 0):
Expand Down
30 changes: 24 additions & 6 deletions TF_object_detection/Manager.py → Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,42 @@
from pyparrot_modified.pyparrot.Bebop import Bebop
from pyparrot_modified.pyparrot.DroneVisionGUI import DroneVisionGUI

while True:
test_mode = input("Would you like to use the test mode? (Y/N): ").capitalize()
if(test_mode == "Y"):
test_mode = True
break

elif(test_mode == "N"):
test_mode = False
break
else:
print("Invalid input, enter either 'Y' or 'N'")


# this object computes the motion and then feeds it to
# 'Move_drone' which then actually moves the drone accordingly

process = Movement_processing()

# creates the bebop object and connects to it
bebop = Bebop()
bebop.connect(5)
success = bebop.connect(5)

# creates the object that moves the drone
move = Move_drone(bebop, process)
move = Move_drone(bebop, process, success)

# creates the GUI that will initiate the video stream
# if testing is true video is streamed from the webcam (this has to be used
# in combination with Drone_Net_Test as the network
vision = DroneVisionGUI(bebop, move=move, process=process, is_bebop=True,
user_args=(bebop,), testing=True)
user_args=(bebop,), testing=test_mode)

# initialises neural net
net = Drone_Net_Test(vision=vision, process=process)
if(test_mode):
net = Drone_Net_Test(vision=vision, process=process)
else:
net = Drone_Net(vision=vision, process=process)

vision.feed_net(net)
move.feed_net(net)
Expand All @@ -42,7 +59,8 @@
print("Starting Vision")
vision.start()

move.start()
print('move started')

# starts feeding movement information to the drone once everything else
# is up and running
move.start()
print('move started')
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ def set_min_box_size(self, min):


class Move_drone(threading.Thread):
def __init__(self, bebop, process):
def __init__(self, bebop, process, success):
"""
:param user_function: user code to run (presumably flies the drone)
:param user_args: optional arguments to the user function
"""
threading.Thread.__init__(self)
self.success = success
self.net = None
self.bebop = bebop
self.process = process
Expand Down Expand Up @@ -168,15 +169,15 @@ def drone_hover(self):
# the function that feeds the movement; runs as a separate thread
def run(self):
# self.bebop.safe_takeoff(5)
self.bebop.set_video_resolutions('rec1080_stream420')
self.bebop.set_video_recording('time')
self.bebop.set_video_stream_mode('low_latency')
#makes the drone patroll if no target is detected

if(self.success):
self.bebop.set_video_resolutions('rec1080_stream480')
self.bebop.set_video_recording('time')
self.bebop.set_video_stream_mode('low_latency')
# makes the drone patroll if no target is detected

# moves the drone as long as it wasn't killed
while(self.killed == False):
if((not self.camera_angle ==-60 or not self.camera_angle == 60) and self.hovering == False):
while (self.killed == False):
if ((not self.camera_angle == -60 or not self.camera_angle == 60) and self.hovering == False):
self.yaw = self.process.get_rotation()
self.tilt = self.process.get_tilt()
self.pitch = self.process.get_pitch()
Expand All @@ -185,14 +186,14 @@ def run(self):
# print("Drone Discombobulated")
# # rotates to track object's left/right movement
# else:
if(self.rotate == True):
if (self.rotate == True):
self.bebop.fly_direct(roll=0, yaw=self.yaw, pitch=self.pitch, vertical_movement=0, duration=0.1)
# moves left/right itself to track object's left/right movement
elif(self.rotate == False):
elif (self.rotate == False):
self.bebop.fly_direct(roll=self.yaw, yaw=0, pitch=self.pitch, vertical_movement=0, duration=0.1)
# if 60 >= self.camera_angle >= -60:
self.bebop.pan_tilt_camera_velocity(tilt_velocity=self.tilt, pan_velocity=0, duration=0.1)
self.camera_angle += self.tilt*0.1
self.camera_angle += self.tilt * 0.1

# all the getter functions:
def get_pitch(self):
Expand Down
1 change: 0 additions & 1 deletion TF_object_detection/README.md

This file was deleted.

File renamed without changes.
Binary file not shown.
242 changes: 242 additions & 0 deletions object_detection/core/standard_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Contains classes specifying naming conventions used for object detection.
Specifies:
InputDataFields: standard fields used by reader/preprocessor/batcher.
DetectionResultFields: standard fields returned by object detector.
BoxListFields: standard field used by BoxList
TfExampleFields: standard fields for tf-example data format (go/tf-example).
"""


class InputDataFields(object):
"""Names for the input tensors.
Holds the standard data field names to use for identifying input tensors. This
should be used by the decoder to identify keys for the returned tensor_dict
containing input tensors. And it should be used by the model to identify the
tensors it needs.
Attributes:
image: image.
image_additional_channels: additional channels.
original_image: image in the original input size.
original_image_spatial_shape: image in the original input size.
key: unique key corresponding to image.
source_id: source of the original image.
filename: original filename of the dataset (without common path).
groundtruth_image_classes: image-level class labels.
groundtruth_image_confidences: image-level class confidences.
groundtruth_boxes: coordinates of the ground truth boxes in the image.
groundtruth_classes: box-level class labels.
groundtruth_confidences: box-level class confidences. The shape should be
the same as the shape of groundtruth_classes.
groundtruth_label_types: box-level label types (e.g. explicit negative).
groundtruth_is_crowd: [DEPRECATED, use groundtruth_group_of instead]
is the groundtruth a single object or a crowd.
groundtruth_area: area of a groundtruth segment.
groundtruth_difficult: is a `difficult` object
groundtruth_group_of: is a `group_of` objects, e.g. multiple objects of the
same class, forming a connected group, where instances are heavily
occluding each other.
proposal_boxes: coordinates of object proposal boxes.
proposal_objectness: objectness score of each proposal.
groundtruth_instance_masks: ground truth instance masks.
groundtruth_instance_boundaries: ground truth instance boundaries.
groundtruth_instance_classes: instance mask-level class labels.
groundtruth_keypoints: ground truth keypoints.
groundtruth_keypoint_visibilities: ground truth keypoint visibilities.
groundtruth_label_weights: groundtruth label weights.
groundtruth_weights: groundtruth weight factor for bounding boxes.
num_groundtruth_boxes: number of groundtruth boxes.
is_annotated: whether an image has been labeled or not.
true_image_shapes: true shapes of images in the resized images, as resized
images can be padded with zeros.
multiclass_scores: the label score per class for each box.
"""
image = 'image'
image_additional_channels = 'image_additional_channels'
original_image = 'original_image'
original_image_spatial_shape = 'original_image_spatial_shape'
key = 'key'
source_id = 'source_id'
filename = 'filename'
groundtruth_image_classes = 'groundtruth_image_classes'
groundtruth_image_confidences = 'groundtruth_image_confidences'
groundtruth_boxes = 'groundtruth_boxes'
groundtruth_classes = 'groundtruth_classes'
groundtruth_confidences = 'groundtruth_confidences'
groundtruth_label_types = 'groundtruth_label_types'
groundtruth_is_crowd = 'groundtruth_is_crowd'
groundtruth_area = 'groundtruth_area'
groundtruth_difficult = 'groundtruth_difficult'
groundtruth_group_of = 'groundtruth_group_of'
proposal_boxes = 'proposal_boxes'
proposal_objectness = 'proposal_objectness'
groundtruth_instance_masks = 'groundtruth_instance_masks'
groundtruth_instance_boundaries = 'groundtruth_instance_boundaries'
groundtruth_instance_classes = 'groundtruth_instance_classes'
groundtruth_keypoints = 'groundtruth_keypoints'
groundtruth_keypoint_visibilities = 'groundtruth_keypoint_visibilities'
groundtruth_label_weights = 'groundtruth_label_weights'
groundtruth_weights = 'groundtruth_weights'
num_groundtruth_boxes = 'num_groundtruth_boxes'
is_annotated = 'is_annotated'
true_image_shape = 'true_image_shape'
multiclass_scores = 'multiclass_scores'


class DetectionResultFields(object):
"""Naming conventions for storing the output of the detector.
Attributes:
source_id: source of the original image.
key: unique key corresponding to image.
detection_boxes: coordinates of the detection boxes in the image.
detection_scores: detection scores for the detection boxes in the image.
detection_multiclass_scores: class score distribution (including background)
for detection boxes in the image including background class.
detection_classes: detection-level class labels.
detection_masks: contains a segmentation mask for each detection box.
detection_boundaries: contains an object boundary for each detection box.
detection_keypoints: contains detection keypoints for each detection box.
num_detections: number of detections in the batch.
raw_detection_boxes: contains decoded detection boxes without Non-Max
suppression.
raw_detection_scores: contains class score logits for raw detection boxes.
"""

source_id = 'source_id'
key = 'key'
detection_boxes = 'detection_boxes'
detection_scores = 'detection_scores'
detection_multiclass_scores = 'detection_multiclass_scores'
detection_classes = 'detection_classes'
detection_masks = 'detection_masks'
detection_boundaries = 'detection_boundaries'
detection_keypoints = 'detection_keypoints'
num_detections = 'num_detections'
raw_detection_boxes = 'raw_detection_boxes'
raw_detection_scores = 'raw_detection_scores'


class BoxListFields(object):
"""Naming conventions for BoxLists.
Attributes:
boxes: bounding box coordinates.
classes: classes per bounding box.
scores: scores per bounding box.
weights: sample weights per bounding box.
objectness: objectness score per bounding box.
masks: masks per bounding box.
boundaries: boundaries per bounding box.
keypoints: keypoints per bounding box.
keypoint_heatmaps: keypoint heatmaps per bounding box.
is_crowd: is_crowd annotation per bounding box.
"""
boxes = 'boxes'
classes = 'classes'
scores = 'scores'
weights = 'weights'
confidences = 'confidences'
objectness = 'objectness'
masks = 'masks'
boundaries = 'boundaries'
keypoints = 'keypoints'
keypoint_heatmaps = 'keypoint_heatmaps'
is_crowd = 'is_crowd'


class TfExampleFields(object):
"""TF-example proto feature names for object detection.
Holds the standard feature names to load from an Example proto for object
detection.
Attributes:
image_encoded: JPEG encoded string
image_format: image format, e.g. "JPEG"
filename: filename
channels: number of channels of image
colorspace: colorspace, e.g. "RGB"
height: height of image in pixels, e.g. 462
width: width of image in pixels, e.g. 581
source_id: original source of the image
image_class_text: image-level label in text format
image_class_label: image-level label in numerical format
object_class_text: labels in text format, e.g. ["person", "cat"]
object_class_label: labels in numbers, e.g. [16, 8]
object_bbox_xmin: xmin coordinates of groundtruth box, e.g. 10, 30
object_bbox_xmax: xmax coordinates of groundtruth box, e.g. 50, 40
object_bbox_ymin: ymin coordinates of groundtruth box, e.g. 40, 50
object_bbox_ymax: ymax coordinates of groundtruth box, e.g. 80, 70
object_view: viewpoint of object, e.g. ["frontal", "left"]
object_truncated: is object truncated, e.g. [true, false]
object_occluded: is object occluded, e.g. [true, false]
object_difficult: is object difficult, e.g. [true, false]
object_group_of: is object a single object or a group of objects
object_depiction: is object a depiction
object_is_crowd: [DEPRECATED, use object_group_of instead]
is the object a single object or a crowd
object_segment_area: the area of the segment.
object_weight: a weight factor for the object's bounding box.
instance_masks: instance segmentation masks.
instance_boundaries: instance boundaries.
instance_classes: Classes for each instance segmentation mask.
detection_class_label: class label in numbers.
detection_bbox_ymin: ymin coordinates of a detection box.
detection_bbox_xmin: xmin coordinates of a detection box.
detection_bbox_ymax: ymax coordinates of a detection box.
detection_bbox_xmax: xmax coordinates of a detection box.
detection_score: detection score for the class label and box.
"""
image_encoded = 'image/encoded'
image_format = 'image/format' # format is reserved keyword
filename = 'image/filename'
channels = 'image/channels'
colorspace = 'image/colorspace'
height = 'image/height'
width = 'image/width'
source_id = 'image/source_id'
image_class_text = 'image/class/text'
image_class_label = 'image/class/label'
object_class_text = 'image/object/class/text'
object_class_label = 'image/object/class/label'
object_bbox_ymin = 'image/object/bbox/ymin'
object_bbox_xmin = 'image/object/bbox/xmin'
object_bbox_ymax = 'image/object/bbox/ymax'
object_bbox_xmax = 'image/object/bbox/xmax'
object_view = 'image/object/view'
object_truncated = 'image/object/truncated'
object_occluded = 'image/object/occluded'
object_difficult = 'image/object/difficult'
object_group_of = 'image/object/group_of'
object_depiction = 'image/object/depiction'
object_is_crowd = 'image/object/is_crowd'
object_segment_area = 'image/object/segment/area'
object_weight = 'image/object/weight'
instance_masks = 'image/segmentation/object'
instance_boundaries = 'image/boundaries/object'
instance_classes = 'image/segmentation/object/class'
detection_class_label = 'image/detection/label'
detection_bbox_ymin = 'image/detection/bbox/ymin'
detection_bbox_xmin = 'image/detection/bbox/xmin'
detection_bbox_ymax = 'image/detection/bbox/ymax'
detection_bbox_xmax = 'image/detection/bbox/xmax'
detection_score = 'image/detection/score'
Loading

0 comments on commit 585f217

Please sign in to comment.