def load_from_img_enhance(img_path): loader = image_tool.ImageTool() new_imgs = [] if 'jpeg' in img_path: img_path = img_path.replace('dcm', 'jpeg') elif 'png' in img_path: img_path = img_path.replace('dcm', 'png') else: raise Exception('Unsupported image format: ', img_path) return loader.load(img_path, grayscale=True).rotate_by_range( (-5, 5)).enhance(0.1).get()
# limitations under the License. import sys import time import numpy as np import traceback from argparse import ArgumentParser from scipy.misc import imread from singa import device from singa import tensor from singa import image_tool from rafiki.agent import Agent, MsgType import model tool = image_tool.ImageTool() num_augmentation = 1 crop_size = 224 mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1] in \ ["PNG", "png", "jpg", "JPG", "JPEG", "jpeg"] def serve(net, label_map, dev, agent, topk=5): '''Serve to predict image labels. It prints the topk food names for each image.