Ejemplo n.º 1
0
 def setUp(self):
     if torch.cuda.is_available():
         print('Running tests with CUDA')
         sl.init_cuda(0)
     else:
         print('Running tests without CUDA')
         sl.init()
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super(TestGradients, self).__init__(*args, **kwargs)
        sl.init()
        self.scene = sl.Scene((640, 480))

        # Taken from first YCB frame
        # NOTE: This is not constant throughout the real dataset!
        fx, fy, cx, cy = 1066.778, 1067.487, 312.9869, 241.3109
        self.scene.set_camera_intrinsics(fx, fy, cx, cy)

        mesh_files = [os.path.join(TESTS_PATH, 'stanford_bunny', 'scene.gltf')]
        self.meshes = []
        for mesh_file in mesh_files:
            mesh = sl.Mesh(mesh_file)

            print("Loaded mesh with bounding box:", mesh.bbox)
            print("center:", mesh.bbox.center, "size:", mesh.bbox.size)

            mesh.center_bbox()
            mesh.scale_to_bbox_diagonal(0.5, 'order_of_magnitude')

            print("normalized:", mesh.bbox)
            print("center:", mesh.bbox.center, "size:", mesh.bbox.size,
                  "diagonal:", mesh.bbox.diagonal)
            self.meshes.append(mesh)
Ejemplo n.º 3
0
def run(ycb_path, ibl_path, plane_texture_path):
    mesh_path = pathlib.Path(ycb_path) / 'models'
    if ibl_path:
        ibl_path = pathlib.Path(ibl_path)

    sl.init()  # use sl.init_cuda() for CUDA interop

    # Load all meshes
    meshes = sl.Mesh.load_threaded(
        [mesh_path / c / 'textured.obj' for c in CLASSES[1:]])

    # Setup class IDs
    for i, mesh in enumerate(meshes):
        mesh.class_index = i + 1

    # Create a scene with matching intrinsics
    scene = sl.Scene(RESOLUTION)
    scene.set_camera_intrinsics(*INTRINSICS)

    for mesh in random.sample(meshes, 10):
        obj = sl.Object(mesh)

        # Override the metallic/roughness parameters so that it gets interesting
        obj.metallic = random.random()
        obj.roughness = random.random()
        scene.add_object(obj)

    # Let them fall in a heap
    scene.simulate_tabletop_scene()

    # Setup lighting
    if ibl_path:
        scene.light_map = sl.LightMap(ibl_path)
    else:
        scene.choose_random_light_position()

    # Display a plane & set background color
    scene.background_plane_size = torch.tensor([3.0, 3.0])
    scene.background_color = torch.tensor([0.1, 0.1, 0.1, 1.0])

    if plane_texture_path:
        scene.background_plane_texture = sl.Texture2D(plane_texture_path)

    # Display interactive viewer
    sl.view(scene)

    # Render a frame
    renderer = sl.RenderPass()
    result = renderer.render(scene)

    # Save as JPEG
    Image.fromarray(result.rgb()[:, :, :3].cpu().numpy()).save('rgb.jpeg')
Ejemplo n.º 4
0
    url = 'http://www.hdrlabs.com/sibl/archive/downloads/Circus_Backstage.zip'
    r = requests.get(url)
    z = zipfile.ZipFile(io.BytesIO(r.content))
    z.extractall(SL_PATH / 'examples')
    print('done.')


if not (SL_PATH / 'examples' / 'Circus_Backstage').exists():
    retrieve_ibl()

import stillleben as sl
import torch
import random
from PIL import Image

sl.init()  # use sl.init_cuda() for CUDA interop

# Load a mesh (the constructor accepts pathlib paths)
mesh = sl.Mesh(SL_PATH / 'tests' / 'stanford_bunny' / 'scene.gltf')

# Meshes can come in strange dimensions - rescale to something reasonable
mesh.scale_to_bbox_diagonal(0.5)

# Create a scene with a few bunnies
scene = sl.Scene((1920, 1080))

for i in range(20):
    obj = sl.Object(mesh)

    # Override the metallic/roughness parameters so that it gets interesting
    obj.metallic = random.random()
Ejemplo n.º 5
0
import torch
import torch.nn.functional as F
import stillleben as sl
import argparse
import json
from pathlib import Path
import visdom
from PIL import Image
import numpy as np
vis = visdom.Visdom(env="synpick_vis", port=8097)
vis.close(env="synpick_vis")

sl.init()


obj_list = ['002_master_chef_can',
            '003_cracker_box',
            '004_sugar_box',
            '005_tomato_soup_can',
            '006_mustard_bottle',
            '007_tuna_fish_can',
            '008_pudding_box',
            '009_gelatin_box',
            '010_potted_meat_can',
            '011_banana',
            '019_pitcher_base',
            '021_bleach_cleanser',
            '024_bowl',
            '025_mug',
            '035_power_drill',
            '036_wood_block',