To receive input values of different sizes, and to randomly select layers

I hope you understand my lack of English.

    self.list5 = [1,2,3,4,5]
    self.floor1list = nn.ModuleList([self.fc1, self.fc2, self.fc3, self.fc4, self.fc5])


def forward(self, x, input_num):
    select = random.sample(self.list5, input_num.item())

    x1 = x[:, :2700]
        
    for j,i in zip(range(input_num), select):
        x1 += self.leaky(self.floor1list[i-1](torch.cat((x[:,:2700], x[:,2700+5400*j:2700+5400*(j+1)]))))
    x1 = self.sigmoid(x1)
    return x1

---> 48         x1 = x[:, :2700]
TypeError: unhashable type: 'slice'

---> 45         select = random.sample(self.list5, input_num.item())
ValueError: only one element tensors can be converted to Python scalars

---> 50         for j,i in zip(range(input_num), [1,2,3,4,5]):
TypeError: only integer tensors of a single element can be converted to an index

batch size = 8
x size = 8x32400
input_num size = 8x1

Force different sizes of inputs to the same size, So I get input_num.
I’d like to select random layers according to input_num.
Errors occur on almost all lines :frowning: :frowning: :frowning: :frowning: :frowning:

Is there a better way?

A slice is a subset of a sequence such as a string, a list , or a tuple . Values in a Python dictionary cannot be sliced like a list. This is because dictionaries can have custom key values. They are not indexed from zero. If you try to slice a dictionary as if it were a list, you’ll encounter the “TypeError: unhashable type: ‘slice’” error. You must directly specify what values you want to access from our dictionary. To do this, refer to the appropriate key names in the dictionary. The other option you have is using a for loop with zip , and range functions. The zip() function will help you to zip the dictionary keys with the range iterator. And the range() function will help you to specify the number of elements you want to access from the dictionary.