How to use the perception.ColorImage.open function in Perception

To help you get started, we’ve selected a few Perception examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BerkeleyAutomation / perception / tests / test_image.py View on Github external
def test_io(self, height=50, width=100):
        color_data = (255 * np.random.rand(height, width, 3)).astype(np.uint8)
        im = ColorImage(color_data, 'a')
        file_root = COLOR_IM_FILEROOT

        # save and load png
        filename = file_root + '.png'
        im.save(filename)
        loaded_im = ColorImage.open(filename)
        self.assertTrue(np.sum(np.abs(loaded_im.data - im.data)) < 1e-5, msg='ColorImage data changed after load png')

        # save and load jpg
        filename = file_root + '.jpg'
        im.save(filename)
        loaded_im = ColorImage.open(filename)

        # save and load npy
        filename = file_root + '.npy'
        im.save(filename)
        loaded_im = ColorImage.open(filename)
        self.assertTrue(np.sum(np.abs(loaded_im.data - im.data)) < 1e-5, msg='ColorImage data changed after load npy')

        # save and load npz
        filename = file_root + '.npz'
        im.save(filename)
        loaded_im = ColorImage.open(filename)
        self.assertTrue(np.sum(np.abs(loaded_im.data - im.data)) < 1e-5, msg='ColorImage data changed after load npz')
github BerkeleyAutomation / perception / tests / test_image.py View on Github external
def test_io(self, height=50, width=100):
        color_data = (255 * np.random.rand(height, width, 3)).astype(np.uint8)
        im = ColorImage(color_data, 'a')
        file_root = COLOR_IM_FILEROOT

        # save and load png
        filename = file_root + '.png'
        im.save(filename)
        loaded_im = ColorImage.open(filename)
        self.assertTrue(np.sum(np.abs(loaded_im.data - im.data)) < 1e-5, msg='ColorImage data changed after load png')

        # save and load jpg
        filename = file_root + '.jpg'
        im.save(filename)
        loaded_im = ColorImage.open(filename)

        # save and load npy
        filename = file_root + '.npy'
        im.save(filename)
        loaded_im = ColorImage.open(filename)
        self.assertTrue(np.sum(np.abs(loaded_im.data - im.data)) < 1e-5, msg='ColorImage data changed after load npy')

        # save and load npz
        filename = file_root + '.npz'
        im.save(filename)
github BerkeleyAutomation / perception / tools / generate_siamese_dataset.py View on Github external
print('TRAIN OBJECTS:', train_objects)
    print('VALIDATION OBJECTS:', validation_objects)

    for objects, directory in [(train_objects, train_dir), (validation_objects, validation_dir)]:
        for objname in objects:
            output_dir = os.path.join(directory, objname)

            if not os.path.exists(output_dir):
                os.makedirs(output_dir)

            image_names = object_images[objname]
            for i, fn in enumerate(image_names):
                print(fn)
                path, base = os.path.split(fn)
                image = ColorImage.open(fn)
                samples = augment(image, num_images_per_view, crop_size, preserve_scale, rotate, keep_full_images)

                # Save original, which is always first sample
                orig_output_dir = os.path.join(orig_dir, objname)
                if not os.path.exists(orig_output_dir):
                    os.makedirs(orig_output_dir)
                orig = samples[0]
                orig.save(os.path.join(orig_output_dir, 'view_{:06d}.png'.format(i)))

                # Save samples
                samples_output_dir = os.path.join(output_dir, 'view_{:06d}'.format(i))
                if not os.path.exists(samples_output_dir):
                    os.makedirs(samples_output_dir)
                for sample in samples:
                    sample_name = uuid.uuid4().hex
                    sample.save(os.path.join(samples_output_dir, '{}.png'.format(sample_name)))
github BerkeleyAutomation / perception / tools / keras_resnet.py View on Github external
import numpy as np
import os
import sys

from perception import ColorImage
from perception.models import ResNet50

DEFAULT_RESNET50_WEIGHTS = '/home/autolab/Public/data/dex-net/data/models/classification/resnet50/weights.h5'

if __name__ == '__main__':
    image_filename = sys.argv[1]

    with open('data/images/imagenet.json', 'r') as f:
        label_to_category = eval(f.read())

    im = ColorImage.open(image_filename)
    resnet = ResNet50(weights_filename=DEFAULT_RESNET50_WEIGHTS)
    out = resnet.predict(im)
    label = resnet.top_prediction(im)
    category = label_to_category[label]

    plt.figure()
    plt.imshow(im.bgr2rgb().data)
    plt.title('Pred: %s' %(category))
    plt.show()

    IPython.embed()
github BerkeleyAutomation / perception / tools / keras_vgg.py View on Github external
import numpy as np
import os
import sys

from perception import ColorImage
from perception.models import VGG16

DEFAULT_VGG16_WEIGHTS = '/home/autolab/Public/data/dex-net/data/models/classification/vgg16/weights.h5'

if __name__ == '__main__':
    image_filename = sys.argv[1]

    with open('data/images/imagenet.json', 'r') as f:
        label_to_category = eval(f.read())

    im = ColorImage.open(image_filename)
    vgg = VGG16(weights_filename=DEFAULT_VGG16_WEIGHTS)
    out = vgg.predict(im)
    label = vgg.top_prediction(im)
    category = label_to_category[label]

    plt.figure()
    plt.imshow(im.bgr2rgb().data)
    plt.title('Pred: %s' %(category))
    plt.show()

    IPython.embed()
github BerkeleyAutomation / perception / tools / predict_class_label.py View on Github external
import numpy as np
import os
import sys

from perception import ColorImage
from perception.models import ClassificationCNN

if __name__ == '__main__':
    model_dir = sys.argv[1]
    model_type = sys.argv[2]
    image_filename = sys.argv[3]

    #with open('data/images/imagenet.json', 'r') as f:
    #    label_to_category = eval(f.read())

    im = ColorImage.open(image_filename)
    cnn = ClassificationCNN.open(model_dir, model_typename=model_type)
    out = cnn.predict(im)
    label = cnn.top_prediction(im)
    #category = label_to_category[label]

    plt.figure()
    plt.imshow(im.bgr2rgb().data)
    plt.title('Pred: %d' %(label))
    plt.axis('off')
    plt.show()