def predict_cam(): model_path = './' global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'Inception-BN') while (True): predictions = global_model.predict_from_cam() print(predictions)
""" import socket import sys, os import json import logging from timeit import default_timer as timer import datetime import load_model import cv2 import csv logging.basicConfig( format='%(asctime)s %(name)-20s %(levelname)-5s %(message)s') model_path = '/greengrass-machine-learning/mxnet/squeezenet/' global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'squeezenet_v1.1') STATS_DIRECTORY = '/home/pi/AWS/mountedStatistics' # write local stats in a csv file def write_local_stats(filename, stats_list): global STATS_DIRECTORY try: filepath = STATS_DIRECTORY.rstrip(os.sep) + os.sep + filename with open(filepath, 'w') as file: writer = csv.writer(file, delimiter=',') writer.writerows(stats_list) except: e = sys.exc_info()[0] print("Exception occured during writting Statistics File: %s" % e) #sys.exit(0)
# long-lived it will run forever when deployed to a Greengrass core. The handler # will NOT be invoked in our example since we are executing an infinite loop. import sys import time import greengrasssdk import platform import os from threading import Timer import load_model client = greengrasssdk.client('iot-data') #model_path = '/greengrass-machine-learning/mxnet/squeezenet/' model_path = './mxnet_models/squeezenetv1.1/' global_model = load_model.ImagenetModel(model_path, 'MXNET', 'synset.txt', 'squeezenet_v1.1') #model_path = '/greengrass-machine-learning/tf/mobilenet/' #model_path = './tf_models/mobilenetv1/' #global_model = load_model.ImagenetModel(model_path, 'TF', 'labels.txt', 'graph.pb', 'MobilenetV1/Predictions/Reshape_1', 'CPU', [('input', (128, 128, 224, 224))]) # When deployed to a Greengrass core, this code will be executed immediately # as a long-lived lambda function. The code will enter the infinite while loop # below. def greengrass_object_classification_run(): if global_model is not None: try: predictions = global_model.predict_from_cam() print predictions #publish predictions
import platform import os from threading import Timer import load_model client = greengrasssdk.client('iot-data') #model_path = '/greengrass-machine-learning/mxnet/squeezenet/' #model_path = './mxnet_models/squeezenetv1.1/' #global_model = load_model.ImagenetModel(model_path, 'MXNET', 'synset.txt', 'squeezenet_v1.1') #model_path = '/greengrass-machine-learning/tf/mobilenet/' model_path = './tf_models/mobilenetv1/' global_model = load_model.ImagenetModel(model_path, 'TF', 'labels.txt', 'graph.pb', 'MobilenetV1/Predictions/Reshape_1', 'CPU', [('input', (128, 128, 224, 224))]) # When deployed to a Greengrass core, this code will be executed immediately # as a long-lived lambda function. The code will enter the infinite while loop # below. def greengrass_object_classification_run(): if global_model is not None: try: predictions = global_model.predict_from_cam() print predictions #publish predictions client.publish(topic='hello/world', payload='New Prediction: {}'.format(
logging.basicConfig( format='%(asctime)s %(name)-20s %(levelname)-5s %(message)s') #model_path = '/greengrass-machine-learning/mxnet/squeezenet/' # ============================================================================= # model_path = '.{}mxnet_models{}squeezenetv1.1{}'.format(os.sep, os.sep, os.sep) # global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'squeezenet_v1.1') # ============================================================================= # ============================================================================= # model_path = '.{}mxnet_models{}caffenet{}'.format(os.sep, os.sep, os.sep) # global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'caffenet') # ============================================================================= model_path = '.{}mxnet_models{}vgg16{}'.format(os.sep, os.sep, os.sep) global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'vgg16') STATS_DIRECTORY = './' image_folderPath = '/home/anirban/Pictures/First2001' # write local stats in a csv file def write_local_stats(filename, stats_list): global STATS_DIRECTORY try: filepath = STATS_DIRECTORY.rstrip(os.sep) + os.sep + filename with open(filepath, 'w') as file: writer = csv.writer(file, delimiter=',') writer.writerows(stats_list) except: e = sys.exc_info()[0]
# will NOT be invoked in our example since the we are executing an infinite loop. # # This can be found on the AWS IoT Console. import greengrasssdk import platform from threading import Timer import time import load_model import sys # Creating a greengrass core sdk client client = greengrasssdk.client('iot-data') model_path = '/greengrass-machine-learning/mxnet/inception_bn/' global_model = load_model.ImagenetModel(model_path + 'synset.txt', model_path + 'Inception-BN') def greengrass_long_run(): if global_model is not None: try: predictions = global_model.predict_from_cam() print predictions #publish predictions client.publish(topic='hello/world', payload='New Prediction: {}'.format( str(predictions))) except: e = sys.exc_info()[0] print("Exception occured during prediction: %s" % e)
import cameratest import load_model print('inside main module') print('main module name' + __name__) #cameratest.TakePicture() #cameratest.UploadToS3() #source_face, matches = cameratest.compare_faces(cameratest.BUCKET, cameratest.KEY_SOURCE, cameratest.BUCKET, cameratest.KEY_TARGET) #print("Source Face ({Confidence}%)".format(**source_face)) #for match in matches: # print ("Target Face ({Confidence}%)".format(**match['Face'])) # print (" Similarity : {}%".format(match['Similarity'])) objtest = load_model.ImagenetModel('synset.txt', 'squeezenet_v1.1') objtest.predict_from_file('cat.jpg')