def main(): ray.init(object_store_memory=4000000000) n_data = 80 test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3)) model = dKeras(ResNet50, weights='imagenet', init_ray=False, wait_for_workers=True, n_workers=4) start_time = time.time() preds = model.predict(test_data) elapsed = time.time() - start_time model.close() time.sleep(2) # # model = ResNet50(weights='imagenet') # preds2 = model.predict(test_data) # # # for i in range(n_data): # # for j,n in enumerate(preds[i]): # # print(n, preds2[i][j]) # # print('-'*80) print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed))
def main(): """ Test out using multiple models at the same time, this case is running ResNet50 and MobileNet """ ray.init() n_data = 20 model1 = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=3) model2 = dKeras(MobileNet, weights='imagenet', wait_for_workers=True, n_workers=3) test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3)) model1.predict(test_data) model2.predict(test_data) model1.close() model2.close()
def main(): n_data = 80 test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3)) model = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=4) start_time = time.time() preds = model.predict(test_data, use_multiprocessing=True, multiprocessing_workers=4) elapsed = time.time() - start_time model.close()
def main(): ray.init() n_data = 20 model = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=3) for i in range(5): test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3)) start_time = time.time() preds_1 = model.predict(test_data) elapsed = time.time() - start_time print(np.asarray(preds_1).shape) print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed)) model.close()
from tensorflow.keras.applications import ResNet50 from dkeras import dKeras from dkeras.utils.qsub_functions import init_pbs_ray import numpy as np import time import ray init_pbs_ray() print(ray.nodes()) data = np.random.uniform(-1, 1, (10000, 224, 224, 3)) start_time = time.time() model = dKeras(ResNet50, init_ray=False, wait_for_workers=True, n_workers=500) elapsed = time.time() - start_time print("Workers initialized after {}".format(elapsed)) start_time = time.time() preds = model.predict(data) elapsed = time.time() - start_time print("Preds after {}".format(elapsed))
model1.predict(test_data) model2.predict(test_data) model1.close() model2.close() if __name__ == "__main__": main() ray.init() n_data = 20 model1 = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=3) model2 = dKeras(MobileNet, weights='imagenet', wait_for_workers=True, n_workers=3) test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3)) model1.predict(test_data) model2.predict(test_data) model1.close() model2.close()
def main(): model_names = { 'densenet121': DenseNet121, 'densenet169': DenseNet169, 'densenet201': DenseNet201, 'inception_v3': InceptionV3, 'inception_resnet_v2': InceptionResNetV2, 'mobilenet': MobileNet, 'mobilenet_v2': MobileNetV2, 'nasnet_large': NASNetLarge, 'nasnet_mobile': NASNetMobile, 'resnet50': ResNet50, 'vgg16': VGG16, 'vgg19': VGG19, 'xception': Xception } # os.environ["KERAS_BACKEND"] = "plaidml.keras.backend" parser = argparse.ArgumentParser() parser.add_argument("--n_data", help="Number of fake datapoints", default=1000, type=int) parser.add_argument("--n_workers", help="Number of Ray workers", default=5, type=int) parser.add_argument("--test", help="0: Local, 1: dKeras", default=1, type=int) parser.add_argument("--search", help="True or False, Find best n_workers", default=False, type=bool) parser.add_argument("--search-pool", help="n workers to search from, separated by commas", default='2,3,5,10,20,25,50,60,100', type=str) parser.add_argument("--model", help="Model options: {}".format(model_names.keys()), default='resnet50', type=str) args = parser.parse_args() n_workers = args.n_workers test_type = args.test n_data = args.n_data model_name = args.model use_search = args.search search_pool = args.search_pool try: search_pool = list(map(int, search_pool.split(','))) except TypeError: raise UserWarning("Search pool arg must be int separated by commas") if not (model_name in model_names.keys()): raise UserWarning("Model name not found: {}, options: {}".format( model_name, model_names)) test_data = np.float16(np.random.uniform(-1, 1, (n_data, 224, 224, 3))) if test_type == 0: model = model_names[model_name]() start_time = time.time() preds = model.predict(test_data) elapsed = time.time() - start_time print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed)) elif test_type == 1: if use_search: results = {} best_time = np.inf best_n_workers = -1 for n in search_pool: model = dKeras(model_names[model_name], wait_for_workers=True, n_workers=n) print("Workers are ready") start_time = time.time() preds = model.predict(test_data) elapsed = time.time() - start_time time.sleep(3) if elapsed < best_time: best_time = elapsed best_n_workers = n results[str(n)] = elapsed model.close() print('{}\nN\tElapsed Time'.format('=' * 80)) for k in results.keys(): print("{}\t{}".format(k, results[k])) print( "{}\nTests completed:\n\tBest N workers: {}\t FPS: {}".format( '=' * 80, best_n_workers, n_data / best_time)) else: model = dKeras(model_names[model_name], wait_for_workers=True, n_workers=n_workers) start_time = time.time() preds = model.predict(test_data) elapsed = time.time() - start_time model.close() time.sleep(3) print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed))