Skip to content
This repository was archived by the owner on Dec 24, 2024. It is now read-only.
This repository was archived by the owner on Dec 24, 2024. It is now read-only.

Can't use CNN? #248

Description

@yumion

Hello, I'm always indebted to machina.

I implement QT-Opt for grasping tasks at PyBullet(https://github.com/bulletphysics/bullet3/blob/master/examples/pybullet/gym/pybullet_envs/baselines/train_kuka_cam_grasping.py).
Observation of this environment is a RGBD image( observation_space = Box(341, 256, 4) ) and action is displacement of x, y, gripper angle( action_space = Box(3,) ).

I built CNN for inputting a image, but I got this error when sampling trajectory.

Traceback (most recent call last):
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/site-packages/machina/samplers/epi_sampler.py", line 126, in mp_sample
    l, epi = one_epi(env, pol, deterministic_flag, prepro)
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/site-packages/machina/samplers/epi_sampler.py", line 51, in one_epi
    ac_real, ac, a_i = pol(torch.tensor(o, dtype=torch.float))
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/site-packages/machina/pols/argmax_qf_pol.py", line 48, in forward
    q, ac = self.qfunc.max(obs)
  File "~/.pyenv/versions/anaconda3-5.3.0/lib/python3.7/site-packages/machina/vfuncs/state_action_vfuncs/cem_state_action_vfunc.py", line 77, in max
    obs = obs.repeat((1, self.num_sampling)).reshape(
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor

I tried on another environment that is like former environment but observation is not RGBD image ( observation_space = Box(9, ) ) (so NN is not CNN but MLP) , but it worked without error.
Is there any problem using CNN...? (or my network is wrong?)
Please give an advice to solve this error.

For reference, here is my NN architecture.

class QTOptNet(nn.Module):
    def __init__(self, observation_space, action_space):
        super(QTOptNet, self).__init__()
        # conv
        self.conv1 = nn.Conv2d(4, 64, kernel_size=6, stride=2, padding=2)
        self.conv2 = nn.Conv2d(64, 64, kernel_size=5, stride=1, padding=2)
        self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1)
        # pool
        self.pool1 = nn.MaxPool2d(3, stride=3)
        self.pool2 = nn.MaxPool2d(2, stride=2)
        # fc
        self.fc1 = nn.Linear(action_space.shape[0], 256)
        self.fc2 = nn.Linear(256, 64)
        self.fc3 = nn.Linear(3136, 64)
        self.fc4 = nn.Linear(64, 64)
        self.output_layer = nn.Linear(64, 1)

    def forward(self, ob, ac):
        ob = ob.transpose(1,2).transpose(1,3)  # convert to channel first
        # observation net
        ob = F.relu(self.conv1(ob))
        ob = self.pool1(ob)
        for i in range(6):
            ob = F.relu(self.conv2(ob))
        ob = self.pool1(ob)
        # action net
        ac = F.relu(self.fc1(ac))
        ac = F.relu(self.fc2(ac))
        ac = ac.view(-1, 64, 1, 1)
        # tiled layer
        ac_tiled = ac.repeat(1, 1, ob.size()[2], ob.size()[3])
        # add action feature
        h = ob + ac_tiled
        for i in range(6):
            h = F.relu(self.conv3(h))
        h = self.pool2(h)
        for i in range(3):
            h = F.relu(self.conv3(h))
        h = h.view(h.size()[0], -1)  # flatten
        h = F.relu(self.fc3(h))
        h = F.relu(self.fc4(h))
        out = torch.sigmoid(self.output_layer(h))
        return out

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions