Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1a3e277
re merge everything on new branch
henrypinkard Nov 11, 2019
5ab1ab2
1 more small cahnge with remerge
henrypinkard Nov 11, 2019
8396723
Merge branch 'master' of https://github.com/fuego-dev/firecam
henrypinkard Nov 11, 2019
a6a68a5
Got docker python running to launch inference image from pyhton
henrypinkard Nov 18, 2019
b46ae2f
update VM build script with new packages
henrypinkard Nov 18, 2019
1a858f1
restore original version of rect_to_squares since cropping for servin…
henrypinkard Nov 18, 2019
0f5aa05
added function for training inceptionv3 with keras
henrypinkard Nov 19, 2019
f28188a
added args and early stopping and model export
henrypinkard Nov 19, 2019
15d11b5
Merge branch 'master' of https://github.com/henrypinkard/firecam
henrypinkard Nov 19, 2019
5d1b3c2
Merge branch 'master' of https://github.com/fuego-dev/firecam
henrypinkard Nov 19, 2019
b9293d8
classifier training changes
invalid-email-address Nov 19, 2019
eb855ee
patched up around some bugs in tf2.0 for training
invalid-email-address Nov 19, 2019
daa82cf
removed tmp files
henrypinkard Nov 20, 2019
c140717
training tweaks
invalid-email-address Dec 1, 2019
f3a3a82
Merge branch 'master' of https://github.com/henrypinkard/firecam
invalid-email-address Dec 1, 2019
ce30ee3
added script for packaging trained model into docker file
henrypinkard Dec 1, 2019
0aeadfd
added script for packaging trained model into docker file
henrypinkard Dec 1, 2019
b6ba479
remove some notes
henrypinkard Dec 2, 2019
ea78e60
revert to old version
henrypinkard Dec 2, 2019
dae03b2
revert to previous version
henrypinkard Dec 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ credentials.json
token.json
local.db
node_modules
#pycharm files
*/.idea/
4 changes: 4 additions & 0 deletions google_cloud/setup_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ apt-get -y install sqlite3
pip3 install -U pip
pip3 install -U psycopg2
pip3 install -U twilio
pip3 install -U numpy
pip3 install -U scipy
pip3 install -U docker


# change timezone
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
Expand Down
5 changes: 4 additions & 1 deletion lib/detection_policies/inception_and_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import settings
import datetime
import math

import docker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the standard license and copyright header at the top of the file. Also, please add one or few lines comment describing the main purpose of this file.


class InceptionV3AndHistoricalThreshold:

Expand All @@ -19,6 +19,9 @@ class InceptionV3AndHistoricalThreshold:

def __init__(self, settings, args, google_services, dbManager):
self.dbManager = dbManager
#start up docker daemon with tf serving
client = docker.from_env()
client.containers.run("inception_serving", detach=True, ports={'8500/tcp': 8500}, tty=True)
self.prediction_service = connect_to_prediction_service(settings.server_ip_and_port)
self.args = args
self.google_services = google_services
Expand Down
62 changes: 62 additions & 0 deletions lib/gcp_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2018 The Fuego Authors.
#
# 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.
# ==============================================================================
"""
Helper functions for Google Cloud Platform
"""

import grpc
import tensorflow as tf
import time

from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
from tensorflow.python.framework import tensor_util

def connect_to_prediction_service(server_ip_and_port):
"""
Connect to a an inference server at given ip address and port. Server could be
a single machine or a Kubernetes cluster
:param server_ip_and_port: string with ip address followed by port (e.g. '34.82.71.243:8500')
:return: PredicitonServiceStub object
"""
# tf.app.flags.DEFINE_string('server', server_ip_and_port, 'PredictionService host:port')
# channel = grpc.insecure_channel(tf.app.flags.FLAGS.server)
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these two lines be deleted? If not, please describe when/how they are needed/useful.

channel = grpc.insecure_channel(server_ip_and_port)
# grpc.secure_channel()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secure_channel definitely sounds better than insecure_channel. Please document what's preventing using secure version.

return prediction_service_pb2_grpc.PredictionServiceStub(channel)

def predict_batch(prediction_service, crops, timing=False):
"""
Run inference on a batch of predicitons
:param crops: N x H x W x 3 uint8 numpy array (e.g. set of crops for a single camera)
:return: N x 2 numpy array of smoke/nonsmoke probabilities
"""

# Send request
# See prediction_service.proto for gRPC request/response details.
request = predict_pb2.PredictRequest()
request.model_spec.name = 'inception'
request.model_spec.signature_name = 'serving_default'
request.inputs['image_batch:0'].CopyFrom(tf.contrib.util.make_tensor_proto(crops, shape=crops.shape))

start = time.time()
result = prediction_service.Predict(request, 1000.0) # 1000 secs timeout
if timing:
print('Inference time {}'.format(time.time() - start))
#convert to numpy
numpy_result = tensor_util.MakeNdarray(result.outputs["import_1/import/InceptionV3/Predictions/Reshape_1"])
return numpy_result
11 changes: 1 addition & 10 deletions lib/rect_to_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
# ==============================================================================
"""
@author: Kinshuk Govil

Simple utility to break up rectangle into squares

"""

import os
Expand All @@ -33,7 +31,6 @@ def rect_to_squares(selectionX0, selectionY0, selectionX1, selectionY1, limitX,
close enough to a square. Also, squares must meet minimium size requiremet of
minSize and must be centered around the selected rectangle. All squares must fit
between (0,0) and (limitX, limitY)

Returns array/list of coordinates for the squares. The coordinates are represented
by 4-tuples (x0,y0,x1,y1)
"""
Expand Down Expand Up @@ -130,15 +127,12 @@ def cutBoxesOld(imgOrig, outputDirectory, imageFileName, callBackFn=None):

def getSegmentRanges(fullSize, segmentSize):
"""Break the given fullSize into ranges of segmentSize

Divide the range (0,fullSize) into multiple ranges of size
segmentSize that are equally spaced apart and have approximately
10% overlap (overlapRatio)

Args:
fullSize (int): size of the full range (0, fullSize)
segmentSize (int): size of each segment

Returns:
(list): list of tuples (start, end) marking each segment's range
"""
Expand Down Expand Up @@ -169,18 +163,15 @@ def getSegmentRanges(fullSize, segmentSize):

def cutBoxesFixed(imgOrig, outputDirectory, imageFileName, callBackFn=None):
"""Cut the given image into fixed size boxes

Divide the given image into square segments of 299x299 (segmentSize below)
to match the size of images used by InceptionV3 image classification
machine learning model. This function uses the getSegmentRanges() function
above to calculate the exact start and end of each square

Args:
imgOrig (Image): Image object of the original image
outputDirectory (str): name of directory to store the segments
imageFileName (str): nane of image file (used as segment file prefix)
callBackFn (function): callback function that's called for each square

Returns:
(list): list of segments with filename and coordinates
"""
Expand Down Expand Up @@ -233,4 +224,4 @@ def test():

# for testing
if __name__=="__main__":
test()
test()
2 changes: 2 additions & 0 deletions sample_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
downloadDir = 'XXX/orig'
archive_storage_bucket = "fuego-firecam-a"

server_ip_and_port = 'localhost:8500' #depends on the specific inference server running on GCP
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"localhost" means do inference locally on same machine. Can also be an IP address to an inference server


teamDriveID = '0ADX9uPkOmsDJUk9PVA' # Fuego Smoke
allPictures = '1SCXFLE25EbQUQMvTcWfeHFU29qxN8WMM' # Pictures - Samples and Full Sets
# smokePictures = '1jq9p2A5BVLh1oWKktpV1oaWTVUU9KmNJ' # Smoke
Expand Down
Loading