mirror of https://github.com/kubeflow/examples.git
fixed parentheses syntax errors
This commit is contained in:
parent
d81d83512a
commit
fdea8cd59e
|
|
@ -16,12 +16,12 @@ def init():
|
|||
else:
|
||||
model_path = '/model/latest.h5'
|
||||
|
||||
print 'Attempting to load model'
|
||||
print('Attempting to load model')
|
||||
model = tf.keras.models.load_model(model_path)
|
||||
model.summary()
|
||||
print 'Done!'
|
||||
print('Done!')
|
||||
|
||||
print 'Initialized model "{}" at {}'.format(model_path, datetime.datetime.now())
|
||||
print('Initialized model "{}" at {}'.format(model_path, datetime.datetime.now()))
|
||||
return model
|
||||
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ def run(raw_data, model):
|
|||
tensor = process_image(img_path, 160)
|
||||
t = tf.reshape(tensor, [-1, 160, 160, 3])
|
||||
o = model.predict(t, steps=1) # [0][0]
|
||||
print o
|
||||
print(o)
|
||||
o = o[0][0]
|
||||
inference_time = datetime.timedelta(seconds=current_time - prev_time)
|
||||
payload = {
|
||||
|
|
@ -45,7 +45,7 @@ def run(raw_data, model):
|
|||
'scores': str(o)
|
||||
}
|
||||
|
||||
print 'Input ({}), Prediction ({})'.format(post['image'], payload)
|
||||
print('Input ({}), Prediction ({})'.format(post['image'], payload))
|
||||
|
||||
return payload
|
||||
|
||||
|
|
@ -65,10 +65,10 @@ def process_image(path, image_size):
|
|||
|
||||
|
||||
def info(msg, char="#", width=75):
|
||||
print ""
|
||||
print char * width
|
||||
print char + " %0*s" % ((-1 * width) + 5, msg) + char
|
||||
print char * width
|
||||
print("")
|
||||
print(char * width)
|
||||
print(char + " %0*s" % ((-1 * width) + 5, msg) + char)
|
||||
print(char * width)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -80,14 +80,14 @@ if __name__ == "__main__":
|
|||
my_model = init()
|
||||
|
||||
for k, v in images.items():
|
||||
print '{} => {}'.format(k, v)
|
||||
print('{} => {}'.format(k, v))
|
||||
|
||||
info('Taco Test')
|
||||
taco = json.dumps({'image': images['tacos']})
|
||||
print taco
|
||||
print(taco)
|
||||
run(taco, my_model)
|
||||
|
||||
info('Burrito Test')
|
||||
burrito = json.dumps({'image': images['burrito']})
|
||||
print burrito
|
||||
print(burrito)
|
||||
run(burrito, my_model)
|
||||
|
|
|
|||
|
|
@ -15,22 +15,22 @@ def check_dir(path):
|
|||
|
||||
def download(source, target, force_clear=False):
|
||||
if force_clear and os.path.exists(target):
|
||||
print 'Removing {}...'.format(target)
|
||||
print('Removing {}...'.format(target))
|
||||
shutil.rmtree(target)
|
||||
|
||||
check_dir(target)
|
||||
|
||||
targt_file = str(Path(target).joinpath('data.zip'))
|
||||
if os.path.exists(targt_file) and not force_clear:
|
||||
print 'data already exists, skipping download'
|
||||
print('data already exists, skipping download')
|
||||
return
|
||||
|
||||
if source.startswith('http'):
|
||||
print "Downloading from {} to {}".format(source, target)
|
||||
print("Downloading from {} to {}".format(source, target))
|
||||
wget.download(source, targt_file)
|
||||
print "Done!"
|
||||
print("Done!")
|
||||
else:
|
||||
print "Copying from {} to {}".format(source, target)
|
||||
print("Copying from {} to {}".format(source, target))
|
||||
shutil.copyfile(source, targt_file)
|
||||
|
||||
print 'Unzipping {}'.format(targt_file)
|
||||
|
|
@ -48,22 +48,22 @@ def process_image(path, image_size=160):
|
|||
|
||||
def walk_images(path, image_size=160):
|
||||
imgs = []
|
||||
print 'Scanning {}'.format(path)
|
||||
print('Scanning {}'.format(path))
|
||||
# find subdirectories in base path
|
||||
# (they should be the labels)
|
||||
labels = []
|
||||
for (_, dirs, _) in os.walk(path):
|
||||
print 'Found {}'.format(dirs)
|
||||
print('Found {}'.format(dirs))
|
||||
labels = dirs
|
||||
break
|
||||
|
||||
for d in labels:
|
||||
path = os.path.join(path, d)
|
||||
print 'Processing {}'.format(path)
|
||||
print('Processing {}'.format(path))
|
||||
# only care about files in directory
|
||||
for item in os.listdir(path):
|
||||
if not item.lower().endswith('.jpg'):
|
||||
print 'skipping {}'.format(item)
|
||||
print('skipping {}'.format(item))
|
||||
continue
|
||||
|
||||
image = os.path.join(path, item)
|
||||
|
|
@ -73,7 +73,7 @@ def walk_images(path, image_size=160):
|
|||
# write out good images
|
||||
imgs.append(image)
|
||||
except Exception as e:
|
||||
print '{}\n{}\n'.format(e, image)
|
||||
print('{}\n{}\n'.format(e, image))
|
||||
|
||||
return imgs
|
||||
|
||||
|
|
@ -88,30 +88,30 @@ if __name__ == "__main__":
|
|||
parser.add_argument('-f', '--force',
|
||||
help='force clear all data', default=False, action='store_true')
|
||||
args = parser.parse_args()
|
||||
print args
|
||||
print(args)
|
||||
|
||||
print 'Using TensorFlow v.{}'.format(tf.__version__)
|
||||
print('Using TensorFlow v.{}'.format(tf.__version__))
|
||||
|
||||
base_path = Path(args.base_path).resolve(strict=False)
|
||||
print 'Base Path: {}'.format(base_path)
|
||||
print('Base Path: {}'.format(base_path))
|
||||
data_path = base_path.joinpath(args.data).resolve(strict=False)
|
||||
print 'Train Path: {}'.format(data_path)
|
||||
print('Train Path: {}'.format(data_path))
|
||||
target_path = Path(base_path).resolve(strict=False).joinpath(args.target)
|
||||
print 'Train File: {}'.format(target_path)
|
||||
print('Train File: {}'.format(target_path))
|
||||
zip_path = args.zipfile
|
||||
|
||||
print 'Acquiring data...'
|
||||
print('Acquiring data...')
|
||||
download('https://aiadvocate.blob.core.windows.net/public/tacodata.zip',
|
||||
str(base_path), args.force)
|
||||
|
||||
if os.path.exists(str(target_path)):
|
||||
print 'dataset text file already exists, skipping check'
|
||||
print('dataset text file already exists, skipping check')
|
||||
else:
|
||||
print 'Testing images...'
|
||||
print('Testing images...')
|
||||
images = walk_images(str(data_path), args.img_size)
|
||||
|
||||
# save file
|
||||
print 'writing dataset to {}'.format(target_path)
|
||||
print('writing dataset to {}'.format(target_path))
|
||||
with open(str(target_path), 'w+') as f:
|
||||
f.write('\n'.join(images))
|
||||
|
||||
|
|
|
|||
|
|
@ -4,26 +4,20 @@ import datetime
|
|||
from io import BytesIO
|
||||
import requests
|
||||
import numpy as np
|
||||
|
||||
from PIL import Image
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
from azureml.core.model import Model
|
||||
|
||||
|
||||
def init():
|
||||
if Model.get_model_path('tacosandburritos'):
|
||||
model_path = Model.get_model_path('tacosandburritos')
|
||||
else:
|
||||
model_path = '/model/latest.h5'
|
||||
|
||||
print 'Attempting to load model'
|
||||
print('Attempting to load model')
|
||||
model = tf.keras.models.load_model(model_path)
|
||||
model.summary()
|
||||
print 'Done!'
|
||||
|
||||
print 'Initialized model "{}" at {}'.format(model_path, datetime.datetime.now())
|
||||
print('Done!')
|
||||
print('Initialized model "{}" at {}'.format(model_path, datetime.datetime.now()))
|
||||
return model
|
||||
|
||||
|
||||
|
|
@ -38,7 +32,7 @@ def run(raw_data, model):
|
|||
tensor = process_image(img_path, 160)
|
||||
t = tf.reshape(tensor, [-1, 160, 160, 3])
|
||||
o = model.predict(t, steps=1) # [0][0]
|
||||
print o
|
||||
print(o)
|
||||
o = o[0][0]
|
||||
inference_time = datetime.timedelta(seconds=current_time - prev_time)
|
||||
payload = {
|
||||
|
|
@ -47,7 +41,7 @@ def run(raw_data, model):
|
|||
'scores': str(o)
|
||||
}
|
||||
|
||||
print 'Input ({}), Prediction ({})'.format(post['image'], payload)
|
||||
print('Input ({}), Prediction ({})'.format(post['image'], payload))
|
||||
|
||||
return payload
|
||||
|
||||
|
|
@ -67,10 +61,10 @@ def process_image(path, image_size):
|
|||
|
||||
|
||||
def info(msg, char="#", width=75):
|
||||
print ""
|
||||
print char * width
|
||||
print char + " %0*s" % ((-1 * width) + 5, msg) + char
|
||||
print char * width
|
||||
print("")
|
||||
print(char * width)
|
||||
print(char + " %0*s" % ((-1 * width) + 5, msg) + char)
|
||||
print(char * width)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -82,14 +76,14 @@ if __name__ == "__main__":
|
|||
my_model = init()
|
||||
|
||||
for k, v in images.items():
|
||||
print '{} => {}'.format(k, v)
|
||||
print('{} => {}'.format(k, v))
|
||||
|
||||
info('Taco Test')
|
||||
taco = json.dumps({'image': images['tacos']})
|
||||
print taco
|
||||
print(taco)
|
||||
run(taco, my_model)
|
||||
|
||||
info('Burrito Test')
|
||||
burrito = json.dumps({'image': images['burrito']})
|
||||
print burrito
|
||||
print(burrito)
|
||||
run(burrito, my_model)
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ from azureml.core.authentication import ServicePrincipalAuthentication
|
|||
|
||||
|
||||
def info(msg, char="#", width=75):
|
||||
print ""
|
||||
print char * width
|
||||
print char + " %0*s" % ((-1 * width) + 5, msg) + char
|
||||
print char * width
|
||||
print("")
|
||||
print(char * width)
|
||||
print(char + " %0*s" % ((-1 * width) + 5, msg) + char)
|
||||
print(char * width)
|
||||
|
||||
|
||||
def get_ws(tenant_id, service_principal_id,
|
||||
service_principal_password, subscription_id, resource_group, workspace):
|
||||
service_principal_password, subscription_id, resource_group, workspace):
|
||||
auth_args = {
|
||||
'tenant_id': tenant_id,
|
||||
'service_principal_id': service_principal_id,
|
||||
|
|
@ -31,17 +31,17 @@ def get_ws(tenant_id, service_principal_id,
|
|||
ws = Workspace.get(workspace, **ws_args)
|
||||
return ws
|
||||
|
||||
|
||||
def run(mdl_path, model_name, ws, tgs):
|
||||
print(ws.get_details())
|
||||
|
||||
print ws.get_details()
|
||||
|
||||
print '\nSaving model {} to {}'.format(mdl_path, model_name)
|
||||
print('\nSaving model {} to {}'.format(mdl_path, model_name))
|
||||
|
||||
# Model Path needs to be relative
|
||||
mdl_path = relpath(mdl_path, '.')
|
||||
|
||||
Model.register(ws, model_name=model_name, model_path=mdl_path, tags=tgs)
|
||||
print 'Done!'
|
||||
print('Done!')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -58,7 +58,7 @@ if __name__ == "__main__":
|
|||
parser.add_argument('-w', '--workspace', help='workspace')
|
||||
args = parser.parse_args()
|
||||
|
||||
print 'Azure ML SDK Version: {}'.format(azureml.core.VERSION)
|
||||
print('Azure ML SDK Version: {}'.format(azureml.core.VERSION))
|
||||
args.model = 'model/' + args.model
|
||||
model_path = str(Path(args.base_path).resolve(
|
||||
strict=False).joinpath(args.model).resolve(strict=False))
|
||||
|
|
@ -80,16 +80,16 @@ if __name__ == "__main__":
|
|||
# printing out args for posterity
|
||||
for i in wsrgs:
|
||||
if i == 'service_principal_password':
|
||||
print '{} => **********'.format(i)
|
||||
print('{} => **********'.format(i))
|
||||
else:
|
||||
print '{} => {}'.format(i, rgs[i])
|
||||
print('{} => {}'.format(i, rgs[i]))
|
||||
|
||||
with(open(str(params_path), 'r')) as f:
|
||||
tags = json.load(f)
|
||||
|
||||
print '\n\nUsing the following tags:'
|
||||
print('\n\nUsing the following tags:')
|
||||
for tag in tags:
|
||||
print '{} => {}'.format(tag, tags[tag])
|
||||
print('{} => {}'.format(tag, tags[tag]))
|
||||
|
||||
rgs['tags'] = tags
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue