TypeError: unsupported operand type(s) for +: 'int' and 'list'

Hi!!!
I am looking for help because I have been stuck at this point for 3 days and I dont know what else to do.
I want to train a NN. In my code after all appropriate installations this error appears.
TypeError: unsupported operand type(s) for +: ‘int’ and ‘list’
I think that the code has no errors because I have find other similar codes in the internet and they did not have problem.
I believe that I dont have install the appropriate versions either from Python, either from Pytorch, something like that…
Can you help me identify and solve the problem?

My code:
def init(self, state_size, action_size, seed, fc1_units=400, fc2_units=300, use_bn=False):
print(type(fc1_units))
print(type(action_size))
“”“Initialize parameters and build model.”""
super(Critic, self).init()
self.seed = torch.manual_seed(seed)
self.use_bn = use_bn
self.fc1 = nn.Linear(state_size, fc1_units)
self.fc2 = nn.Linear(fc1_units + action_size, fc2_units) ERROR
self.fc3 = nn.Linear(fc2_units, 1)
if self.use_bn:
self.bn1 = nn.BatchNorm1d(fc1_units)
self.bn2 = nn.BatchNorm1d(fc2_units)

    self.reset_parameters()

Error :
<class ‘int’>
<class ‘list’>
Traceback (most recent call last):
File “maddpg_trainer.py”, line 151, in
main()
File “maddpg_trainer.py”, line 143, in main
agent = MADDPGAgentTrainer(state_shape, action_size, num_agents, writer=writer, random_seed=48, dirname=dirname, print_every=100, model_path=args.model)
File “C:\ML-Agents\Katorina\maddpg.py”, line 331, in init
for i in range(self.num_agents)]
File “C:\ML-Agents\Katorina\maddpg.py”, line 331, in
for i in range(self.num_agents)]
File “C:\ML-Agents\Katorina\maddpg.py”, line 86, in init
random_seed, fc1_units=self.config[‘FC1’], fc2_units=self.config[‘FC2’]
File “C:\ML-Agents\Katorina\models.py”, line 87, in init
self.fc2 = nn.Linear(fc1_units + action_size, fc2_units)
TypeError: unsupported operand type(s) for +: ‘int’ and 'list’

Thank you in advance!

If i understand correctly; you want to add number into the List than it would be

self.fc2 = nn.Linear([fc1_units] + action_size, fc2_units)

Hi!!
Thank you very much for answering me!
Actually they are integers. Their initialization is this line

The problem is that action_size is actually not an integer. You even printed it’s type here:

getting this result:

If you want to use the + operator on a list and an integer you can either add the number into the List as Dishin_Goyani explained.

Or take one item from the List (assuming there are integers in your list) and add it together with your fc1_units. Like:

self.fc2 = nn.Linear(fc1_units + action_size[0], fc2_units)

Unfortunately, nothing works.
In the first case with this change : self.fc2 = nn.Linear([fc1_units] + action_size, fc2_units)
I get this error

File “C:\Users\Danae\Anaconda3\envs\effort7\lib\site-packages\torch\nn\modules\linear.py”, line 41, in init
self.weight = Parameter(torch.Tensor(out_features, in_features))
TypeError: ‘list’ object cannot be interpreted as an integer

and with this change self.fc2 = nn.Linear(fc1_units + action_size[0], fc2_units)
I get this error

File “C:\Users\Danae\Anaconda3\envs\effort7\lib\site-packages\torch\nn\modules\linear.py”, line 41, in init
self.weight = Parameter(torch.Tensor(out_features, in_features))
RuntimeError: CUDA error (35): CUDA driver version is insufficient for CUDA runtime version

Can you maybe print action_size. Just so I can see what this list contains.
Just do the same as you did with

but remove the type() so it’s just print(action_size) and post the result.

But judging from this error

it actually should have worked, but there might be a problem with CUDA or graphics driver version, or you are trying to use CUDA when you are supposed to use cpu (e.g. if you are on a cpu installation of pytorch or don’t have a compatible gpu)

<class ‘int’>
<class ‘list’>
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
Traceback (most recent call last):
File “maddpg_trainer.py”, line 151, in
main()
File “maddpg_trainer.py”, line 143, in main
agent = MADDPGAgentTrainer(state_shape, action_size, num_agents, writer=writer, random_seed=48, dirname=dirname, print_every=100, model_path=args.model)
File “C:\ML-Agents\Katorina\maddpg.py”, line 331, in init
for i in range(self.num_agents)]
File “C:\ML-Agents\Katorina\maddpg.py”, line 331, in
for i in range(self.num_agents)]
File “C:\ML-Agents\Katorina\maddpg.py”, line 86, in init
random_seed, fc1_units=self.config[‘FC1’], fc2_units=self.config[‘FC2’]
File “C:\ML-Agents\Katorina\models.py”, line 88, in init
self.fc2 = nn.Linear(fc1_units + action_size, fc2_units)
TypeError: unsupported operand type(s) for +: ‘int’ and ‘list’

This is the result of print(action_size)
I installed torch with this command without gpu.

conda install pytorch torchvision cpuonly -c pytorch

I had also tried to install a previous version of pytorch because I believed that this was the reason of the errors.
Installing without CUDA
conda install pytorch=0.4.1 -c pytorch

ok. I have no idea what action_size is supposed to be, but

will definitely work (as in, it will no longer give you this error)

As for this error message:

I am not quite sure. It could be multiply things. The only thing I could say from the top of my head is:
Are you maybe loading a model like so model = torch.load(pathname)?
If so, you might wanna try and include a map_location like so: model = torch.load(pathname, map_location=map_location)
For CPU (your case I am assuming) that would be:
model = torch.load(pathname, map_location='cpu')

action_size is an integer that represents the dimension of each action
Do you mean something like that?

logger = logging.getLogger(name)
device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)
logger.info(‘Using device: {}’.format(device))