Exemple #1
0
    parser = argparse.ArgumentParser()

    parser.add_argument('-x',
                        '--width',
                        type=int,
                        default=640,
                        help='Width of the generated images')
    parser.add_argument('-y',
                        '--height',
                        type=int,
                        default=480,
                        help='Height of the generated images')

    args = parser.parse_args()

    generator = SheetMetalGenerator(args)
    image, mask = generator.generate()

    assert len(image.shape) == 3
    assert image.shape[0] == args.height
    assert image.shape[1] == args.width
    assert image.shape[2] == 3
    assert image.dtype == np.float64

    assert len(mask.shape) == 2
    assert mask.shape[0] == args.height
    assert mask.shape[1] == args.width
    assert mask.dtype == np.float64

    utils.show_image([image, 'Sheet metal'], [mask, 'Specimen mask'])
Exemple #2
0
    #
    # Parse command line arguments
    #
    parser = argparse.ArgumentParser ()

    parser.add_argument ('-x', '--width',   type=int, default=640,  help='Width of the generated images')
    parser.add_argument ('-y', '--height',  type=int, default=480,  help='Height of the generated images')

    generator.background.BackgroundGenerator.add_to_args_definition (parser)

    args = parser.parse_args ()

    parts = [generator.background.BackgroundGenerator.create (args),
             generator.fixture.FixtureGenerator (args)]

    source = generator.generator.StackedGenerator (args, parts)
    image, mask = source.generate ()

    assert len (mask.shape) == 3
    assert image.shape[0] == args.height
    assert image.shape[1] == args.width
    assert image.shape[2] == 3
    assert image.dtype == np.float64

    assert len (mask.shape) == 2
    assert mask.shape[0] == args.height
    assert mask.shape[1] == args.width
    assert mask.dtype == np.float64

    utils.show_image ([image, 'Fixture'], [mask, 'Mask'])
if args.performance:
    start_time = time.process_time()

    images, masks = next(data.generate)
    model.predict(images)

    elapsed_time = (time.process_time() - start_time) / (10 * args.performance)

    print('Single run duration: {0:.4f} s'.format(elapsed_time))

start_time = time.process_time()

result = model.predict(images)[0]

print('Duration: {0:.4f}s'.format((time.process_time() - start_time) / 10))

print(result.shape)

mask = np.zeros(result.shape[0:2])

mask[result[:, :, 0] > 0.5] = 1.0
mask[result[:, :, 1] > 0.5] = 0.5

utils.show_image([images[0], 'Generated image'],
                 [mask, 'Predicted specimen features'])

#
# Tensorflow termination bug workaround
#
gc.collect()
Exemple #4
0
    #
    parser = argparse.ArgumentParser()

    parser.add_argument('-x',
                        '--width',
                        type=int,
                        default=640,
                        help='Width of the generated images')
    parser.add_argument('-y',
                        '--height',
                        type=int,
                        default=480,
                        help='Height of the generated images')
    parser.add_argument('-c',
                        '--color',
                        type=float,
                        default=0.3,
                        help='Color seed')
    parser.add_argument('-s',
                        '--shine',
                        type=float,
                        default=0.1,
                        help='Shine seed')

    args = parser.parse_args()

    texture_creator = MetalTextureCreator(args.width, args.height, args.color,
                                          args.shine)
    image = texture_creator.create()
    utils.show_image([image, 'Metal texture'])
Exemple #5
0
    args = parser.parse_args()

    #
    # Instantiate generator class from command line arguments
    #
    generator = BackgroundGenerator.create(args)

    if args.profile:
        pr = cProfile.Profile()
        pr.enable()

    #
    # Generate image probe
    #
    image, mask = generator.generate()

    assert mask is None
    assert image.shape[0] == args.height
    assert image.shape[1] == args.width
    assert image.shape[2] == 3
    assert image.dtype == np.float64

    if args.profile:
        pr.disable()

        stats = pstats.Stats(pr, stream=sys.stdout).sort_stats('cumulative')
        stats.print_stats()

    utils.show_image([image, 'Generated background'])