コード例 #1
0
def plot_predictions(samples):
    (lables, interpolations) = model.predict(samples)
    for arg, images in enumerate(zip(interpolations, samples)):
        interpolated, image = images
        interpolated = (interpolated * 255).astype('uint8')
        image = (image * 255).astype('uint8')
        write_image('images/interpolated_image_%03d.png' % arg, interpolated)
        write_image('images/original_image_%03d.png' % arg, image)
コード例 #2
0
    os.makedirs(save_path)

# setting callbacks
log = CSVLogger(os.path.join(save_path, '%s.log' % model_name))
stop = EarlyStopping('loss', patience=args.stop_patience, verbose=1)
plateau = ReduceLROnPlateau('loss', patience=args.plateau_patience, verbose=1)
model_path = os.path.join(save_path, '%s_weights.hdf5' % model_name)
save = ModelCheckpoint(
    model_path, 'loss', verbose=1, save_best_only=True, save_weights_only=True)

# setting drawing callbacks
images = (sequence.__getitem__(0)[0]['input_image'] * 255).astype('uint8')
for arg, image in enumerate(images):
    image_name = 'image_%03d.png' % arg
    image_path = os.path.join(save_path, 'original_images/' + image_name)
    write_image(image_path, image)
inferencer = AutoEncoderPredictor(model)
draw = DrawInferences(save_path, images, inferencer)

# saving hyper-parameters and model summary as text files
print(save_path)
with open(os.path.join(save_path, 'hyperparameters.json'), 'w') as filer:
    json.dump(args.__dict__, filer, indent=4)
with open(os.path.join(save_path, 'model_summary.txt'), 'w') as filer:
    model.summary(print_fn=lambda x: filer.write(x + '\n'))

# model optimization
model.fit_generator(
    sequence,
    steps_per_epoch=args.steps_per_epoch,
    epochs=args.max_num_epochs,
コード例 #3
0
from paz.pipelines import DetectSingleShot
from paz.models.detection import SSD300
from paz.backend.image import load_image, show_image, write_image


class SSD300SolarPanel(DetectSingleShot):
    def __init__(self,
                 weights_path,
                 score_thresh=0.50,
                 nms_thresh=0.45,
                 draw=True):
        class_names = ['background', 'solar_panel']
        model = SSD300(len(class_names), None, None)
        model.load_weights(weights_path)
        super(SSD300SolarPanel, self).__init__(model,
                                               class_names,
                                               score_thresh,
                                               nms_thresh,
                                               draw=draw)


# weights_path = 'trained_models/SSD300/weights.172-3.15.hdf5'
weights_path = 'trained_models/SSD300/weights.141-2.66.hdf5'
detect = SSD300SolarPanel(weights_path)
image_paths = glob.glob('datasets/test_solar_panel/*.jpg')
for image_arg, image_path in enumerate(image_paths):
    image = load_image(image_path)
    results = detect(image)
    # show_image(results['image'])
    write_image('results/image_%s.png' % image_arg, results['image'])
コード例 #4
0
ファイル: train_symmetric.py プロジェクト: oarriaga/paz
image_directory = os.path.join(experiment_path, 'original_images')
if not os.path.exists(image_directory):
    os.makedirs(image_directory)

images = []
for image_arg in range(args.num_test_images):
    image, alpha, masks = renderer.render()
    image = np.copy(image)  # TODO: renderer outputs unwritable numpy arrays
    masks = np.copy(masks)  # TODO: renderer outputs unwritable numpy arrays
    image_filename = 'image_%03d.png' % image_arg
    masks_filename = 'masks_%03d.png' % image_arg
    image_directory = os.path.join(experiment_path, 'original_images')
    image_filename = os.path.join(image_directory, image_filename)
    masks_filename = os.path.join(image_directory, masks_filename)
    write_image(image_filename, image)
    write_image(masks_filename, masks)
    images.append(image)

# setting drawing callback
camera = Camera()
camera.distortion = np.zeros((4))
camera.intrinsics_from_HFOV(image_shape=(args.image_size, args.image_size))
object_sizes = renderer.mesh.mesh.extents * 100  # from meters to milimiters
# camera.intrinsics = renderer.camera.camera.get_projection_matrix()[:3, :3]
draw_pipeline = RGBMaskToPose6D(model, object_sizes, camera, draw=True)
draw = DrawInferences(experiment_path, images, draw_pipeline)
callbacks = [log, stop, save, plateau, draw]

# saving hyper-parameters and model summary
with open(os.path.join(experiment_path, 'hyperparameters.json'), 'w') as filer: