alexfrom0815 / Online-3D-BPP-PCT

Code implementation of "Learning Efficient Online 3D Bin Packing on Packing Configuration Trees". We propose to enhance the practical applicability of online 3D Bin Packing Problem (BPP) via learning on a hierarchical packing configuration tree which makes the deep reinforcement learning (DRL) model easy to deal with practical constraints and well-performing even with continuous solution space.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to visualized the results?

Bailey-24 opened this issue · comments

I want to debug, but I couldn't understand what's going on? so how to visualize the results?
Thank in advance.

@Bailey-24
I modify the discrete observation environment (pct_envs/PctDiscrete0)/bin3D.py) by adding render() like this;

    def render(self, mode=None, wait_time=10):
    
            # mode is ignored
    
            vis_plain = self.space.plain
    
            # Create the image from the array
            image = np.empty((len(vis_plain), len(vis_plain[0]), 3), dtype=np.uint8)  # Create an empty image with 3 channels (RGB)
            for i in range(len(vis_plain)):
                for j in range(len(vis_plain[0])):
                    image[i][j] = self.colors_map[vis_plain[i][j]]  # Set the pixel color based on the value in the array
    
            # Resize the image
            expanded_image  = cv2.resize(image, (30*image.shape[1], 30*image.shape[0]), interpolation=cv2.INTER_NEAREST)

            # Write the values on each cell
            font = cv2.FONT_HERSHEY_SIMPLEX  # Define the font
            font_scale = 0.5  # Define the font scale
            thickness = 1  # Define the line thickness
            for i in range(len(vis_plain)):
                for j in range(len(vis_plain[0])):
                    value = str(vis_plain[i][j])  # Convert the value to a string
                    (x, y) = (j * 30 + 5, i * 30 + 20)  # Calculate the position of the text
                    cv2.putText(expanded_image, value, (x, y), font, font_scale, (0, 0, 0), thickness, cv2.LINE_AA)
    
            # Display the image
            cv2.imshow('Bin packing view', expanded_image)
            cv2.waitKey(wait_time)

`

Hi, there is a bug.
AttributeError: 'PackingDiscrete' object has no attribute 'colors_map'

how do you initial and process the colors_map in the env.

Thanks in advance.

@Bailey-24
Hi i'm afraid that i forgot the colors_map
in the PackingDiscrete , I also added the colors_map on the last line def __init__()

``

class PackingDiscrete(gym.Env):
    def __init__(self,
                setting,
                container_size=(10, 10, 10),
                item_set=None, data_name=None, load_test_data=False,
                internal_node_holder=80, leaf_node_holder=50, next_holder=1, shuffle=False,
                LNES = 'EMS',
                **kwags):

        self.internal_node_holder = internal_node_holder
        self.leaf_node_holder = leaf_node_holder
        self.next_holder = next_holder

        self.shuffle = shuffle
        self.bin_size = container_size
        self.size_minimum = np.min(np.array(item_set))
        self.setting = setting
        self.item_set = item_set
        if self.setting == 2: self.orientation = 6
        else: self.orientation = 2
        
        # The class that maintains the contents of the bin.
        self.space = Space(*self.bin_size, self.size_minimum, self.internal_node_holder)

        # Generator for train/test data
        if not load_test_data:
            assert item_set is not None
            self.box_creator = RandomBoxCreator(item_set)
            assert isinstance(self.box_creator, BoxCreator)
        if load_test_data:
            self.box_creator = LoadBoxCreator(data_name)

        self.test = load_test_data
        self.observation_space = gym.spaces.Box(low=0.0, high=self.space.height,
                                                shape=((self.internal_node_holder + self.leaf_node_holder + self.next_holder) * 9,))
        self.action_space = None
        self.next_box_vec = np.zeros((self.next_holder, 9))

        self.LNES = LNES  # Leaf Node Expansion Schemes: EMS (recommend), EV, EP, CP, FC
        
        # Define the color map
        # Define the data type as 8-bit unsigned integer
        self.colors_map = np.array([[20*vidx, 0, 255-20*vidx] for vidx in reversed(range(11))], dtype=np.uint8)    

`