def main(): training_set = load_image() training_set = mask(training_set) # plt.imshow(training_set[0]) # plt.show() results = googlenet(training_set, dropout_keep_prob=0.4, num_classes=2, is_training=True, restore_logits = None, scope='') print results[0]
def upload_image(): if request.method == "POST": print(request.files) f = request.files['image'] path = './uploads/' + f.filename f.save(path) #Preprocessing tasks resized, original = load_image(path) if (resized is not None): T, warped = wrap_transform(resized, original) if T is not None: keyval = detectTexts(T) print(keyval) return dict(status='success', data=keyval, msg='success', code='200') else: keyval = detectTexts(resized) print(keyval) if (bool(keyval)): return dict(status='success', data=keyval, msg='success', code='200') else: return dict(status='failed', data=keyval, msg='failed', code='400') else: return dict(status='failed', msg="Image not found", code='400', data={})
def infer_from_path(image_path, model, prior_boxes): target_size = model.input_shape[1:3] image_array, original_image_shape = load_image(image_path, target_size) detections = _infer(image_array, model, original_image_shape, prior_boxes) return detections
type=int, default=10, help='Number of iterations') ap.add_argument('--alpha', type=float, default=0.01, help='The ratio of content to style, default is 1e-2.' 'Increase for more content, decrease for more style.') ap.add_argument( '--afactor', type=int, default=3, help='Abstract factor. How abstract do you want your image to be?') return ap.parse_args() if __name__ == '__main__': args = parse_args() style_image = load_image(args.style) content_image = load_image(args.content) run(style_image=style_image, content_image=content_image, save_path=args.save_path, height=args.size, width=args.size, iterations=args.iter, content_weight=args.alpha, style_weight=1.0, total_variation_weight=0.2, abstract_factor=args.afactor)
# Make Detections results = holistic.process(image) # print(results.face_landmarks) # Recolor image back to BGR for rendering image.flags.writeable = True image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) # Pose Detections mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS ) # get body pose pose_features = extract_features(load_image(image)) if np.nan not in pose_features.values(): try: predicted_pose = model.predict_proba( np.atleast_2d([*pose_features.values()]) ) result = {"time": time} for key, val in zip(model.classes_, predicted_pose.flatten()): result[key] = val best_pred = get_best_predicition(predicted_pose.flatten(), model.classes_, thresholt=0.05) if best_pred:
num_ground_truth_boxes = 0 class_decoder = get_arg_to_class(class_names) num_classes = len(class_names) data_manager = DataManager(dataset_name, split='test', class_names=selected_classes) ground_truth_data = data_manager.load_data() difficult_data_flags = data_manager.parser.difficult_objects image_names = sorted(list(ground_truth_data.keys())) for image_name in image_names: ground_truth_sample = ground_truth_data[image_name] image_prefix = data_manager.parser.images_path image_path = image_prefix + image_name original_image_array = cv2.imread(image_path) image_array, original_image_size = load_image(image_path, input_shape) # original_image_size = original_image_size[::-1] image_array = substract_mean(image_array) predicted_data = predict(model, image_array, prior_boxes, original_image_size, num_classes, class_threshold, iou_nms_threshold) ground_truth_sample = denormalize_box(ground_truth_sample, original_image_size) difficult_objects = difficult_data_flags[image_name] difficult_objects = np.asarray(difficult_objects, dtype=bool) num_ground_truth_boxes += np.sum(np.logical_not(difficult_objects)) if predicted_data is None: continue """ draw_image_boxes(predicted_data, original_image_array,
from models import SSD300 from preprocessing import load_image from datasets import get_class_names from datasets import get_arg_to_class # from utils.inference import infer_from_path from utils.inference import infer_from_array from visualizer import draw_image_boxes # parameters dataset_name = 'VOC2007' # image_path = '../images/boys.jpg' image_path = '../images/voc_cars.jpg' weights_path = '../trained_models/SSD300_weights.hdf5' model = SSD300(weights_path=weights_path) class_names = get_class_names(dataset_name) arg_to_class = get_arg_to_class(class_names) original_image_array = load_image(image_path)[0] # detections = infer_from_path(image_path, model) target_size = model.input_shape[1:3] image_array, original_image_shape = load_image(image_path, target_size) detections = infer_from_array(image_array, model, original_image_shape) draw_image_boxes(detections, original_image_array, arg_to_class)
def reshape_pred(pred): return pred.reshape(224,224,2)[:,:,1] if __name__=="__main__": """ This script makes predictions on a list of inputs with a pre-trained model, and saves them as transparency masks over the original image. # Example: $ python predict.py image1.jpg image2.jpg """ imgs = args.imgs img_sz = args.img_size input_shape = (224,224,3) img_input = Input(shape=input_shape) x = create_tiramisu(2, img_input, nb_layers_per_block=[4,5,7,10,12,15], p=0.2, wd=1e-4) model = Model(img_input, x) model.compile(loss='categorical_crossentropy', optimizer=keras.optimizers.RMSprop(1e-3), metrics=["accuracy"], sample_weight_mode='temporal') model.load_weights(args.model) for i, img in enumerate(imgs): full_img = load_image(img, img_sz) full_img_r, full_pred = waldo_predict(full_img) mask = prediction_mask(full_img_r, full_pred) mask.save(os.path.join(args.output_path, 'output_'+str(i)+'.png'))