def main(): args = get_parser() # Getting data to predict on if os.path.isfile(args.images_path): data = load_image(args.images_path, args.image_size) image_names = [args.images_path] data = data.reshape(-1, args.image_size, args.image_size, 1) else: data, image_names = load_images(args.images_path, args.image_size) # Creating model model = create_model(image_size=args.image_size, weights_path=args.weights_path) # Predicting head_root, head_vowel, head_consonant = model.predict(data, verbose=1) head_root = np.argmax(head_root, axis=1) head_vowel = np.argmax(head_vowel, axis=1) head_consonant = np.argmax(head_consonant, axis=1) # Creating and saving resulting DataFrame result_df = pd.DataFrame() result_df['image_name'] = image_names result_df['head_root'] = head_root result_df['head_vowel'] = head_vowel result_df['head_consonant'] = head_consonant result_df.to_csv('result.csv', index=False)
def main(_): # Retrieve parameters config = get_parameters() #prepare data word_table, data = dataset.prepare_data(config) # Preprocess all images test_data = pre.load_image('data/laska.png', (224, 224)) test_data = np.array([test_data]) # Build model. model = ImageCaptioner(config, word_table) # model.train(train_data) model.test(test_data)
def get_batch_from_txt_files_(self): self.index += 1 #for i, f in enumerate(fs): img = load_image(osp.join('/home/ubuntu/3d-testing/InterHand2.6M/main/', self.fs[self.index]).strip()) box = self.bs[self.index].split(",") bbox = [] for b in box: bbox.append(float(b.replace("\n", ""))) img, inv_trans = augmentation(img, np.array(bbox), None, None, None, 'test', None) img = self.transform(img.astype(np.float32))/255. # image = cv2.imread(osp.join('/home/ubuntu/3d-testing/InterHand2.6M/main/', self.fs[self.index]).strip()) # image = cv2.rectangle(image, (int(bbox[0]), int(bbox[1])), (int(bbox[0])+int(bbox[2]), int(bbox[0]) + int(bbox[3])), (255,0,0), 3) # print(cv2.imwrite("bbox_testing/" + str(self.index)+".jpg", image)) return img, osp.join('/home/ubuntu/3d-testing/InterHand2.6M/main/', self.fs[self.index]).strip(), inv_trans
from data_augmentation import SSDAugmentation from utils.datasets import DataManager from utils.preprocessing import load_image from utils.datasets import get_arg_to_class from utils.visualizer import draw_image_boxes import cv2 # import numpy as np size = 300 dataset_name = 'VOC2007' class_names = ['background', 'aeroplane'] class_to_arg = get_arg_to_class(class_names) # transformer = SSDAugmentation(size, mean=(104, 117, 123)) transformer = SSDAugmentation(size, mean=(0, 0, 0)) data_manager = DataManager(dataset_name, class_names) data = data_manager.load_data() for image_key in data.keys(): image_path = data_manager.image_prefix + image_key print(cv2.imread(image_path)) image_array = load_image(image_path, (size, size))[0] original_image_array = load_image(image_path, None)[0] ground_truth_data = data[image_key] boxes = ground_truth_data[:, :4] labels = ground_truth_data[:, 4:] transformed_data = transformer(image_array, boxes, labels) image_array, boxes, labels = transformed_data # image_array = image_array[:, :, ::-1] image_array = image_array.astype('uint8') draw_image_boxes(boxes, image_array, class_to_arg, normalized=True)
from utils.data_augmentation import HorizontalFlip from utils.data_augmentation import ToPercentCoords from utils.data_augmentation import Resize from utils.data_augmentation import SubtractMeans from utils.preprocessing import load_image from utils.preprocessing import B_MEAN, G_MEAN, R_MEAN from datasets import DataManager import matplotlib.pyplot as plt data_manager = DataManager('VOC2007', 'train') class_names = data_manager.class_names train_data = data_manager.load_data() image_path = sorted(list(train_data.keys()))[7] box_data = train_data[image_path] image_array = load_image(image_path, RGB=False).copy() data = (image_array, box_data[:, :4], box_data[:, 4:]) convert_from_ints = ConvertFromInts() to_absolute_coords = ToAbsoluteCoords() photometric_distort = PhotometricDistort2() expand = Expand((B_MEAN, G_MEAN, R_MEAN)) random_sample_crop = RandomSampleCrop() horizontal_flip = HorizontalFlip() to_percent_coords = ToPercentCoords() resize = Resize(300) subtract_means = SubtractMeans((B_MEAN, G_MEAN, R_MEAN)) plt.imshow(image_array[..., ::-1]) plt.show() data = convert_from_ints(*data)
selected_classes = [class_names[0]] + [class_names[ground_truth_class_arg]] num_ground_truth_boxes = 0 class_decoder = get_arg_to_class(class_names) num_classes = len(class_names) data_manager = DataManager(dataset_name, selected_classes, data_prefix, image_prefix) ground_truth_data = data_manager.load_data() difficult_data_flags = data_manager.parser.difficult_objects image_names = sorted(list(ground_truth_data.keys())) # print('Number of images found:', len(image_names)) for image_name in image_names: ground_truth_sample = ground_truth_data[image_name] image_prefix = data_manager.image_prefix image_path = image_prefix + image_name image_array, original_image_size = load_image(image_path, input_shape) image_array = preprocess_images(image_array) predicted_data = predict(model, image_array, prior_boxes, original_image_size, 21, class_threshold, iou_threshold) ground_truth_sample = denormalize_box(ground_truth_sample, original_image_size) ground_truth_boxes_in_image = len(ground_truth_sample) 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: # print('Zero predictions given for image:', image_name) continue #plt.imshow(original_image_array.astype('uint8')) #plt.show()
ground_truth_data = dataset_manager.load_data() class_names = dataset_manager.class_names print('Found:', len(ground_truth_data), 'images') print('Class names: \n', class_names) # prior boxes # ------------------------------------------------------------------ # model = SSD300() prior_boxes = create_prior_boxes() print('Prior boxes shape:', prior_boxes.shape) print('Prior box example:', prior_boxes[777]) image_path = '../images/fish-bike.jpg' # input_shape = model.input_shape[1:3] input_shape = (300, 300) image_array = load_image(image_path, input_shape) prior_boxes = to_point_form(prior_boxes) box_coordinates = prior_boxes[7010:7015, :] plot_box_data(box_coordinates, image_array) plt.imshow(image_array) plt.show() # ground truth # ------------------------------------------------------------------ image_name, box_data = random.sample(ground_truth_data.items(), 1)[0] print('Data sample: \n', box_data) # image_path = dataset_manager.images_path + image_name image_path = image_name arg_to_class = dataset_manager.arg_to_class colors = get_colors(len(class_names)) image_array = load_image(image_path, input_shape)