1

I have a python caffe object called net. Normally in python, net was setup for its layer as

net.conv1_1 = L.Convolution(net[from_layer], num_output=64, pad=1, kernel_size=3, **kwargs)

But for me, I have layer names as variables in the program and not hard coded. So how I can join layer name conv1 to net. I did as

join( net.,'%s'%(layer[lIdx]['l_name']))=L.Convolution(net[layer[lIdx-1]['l_name']], num_output=layer[lIdx]['n_channels'], pad=layer[lIdx]['l_struct'][2], kernel_size=layer[lIdx]['l_struct'][0], **kwargs)

This join( net.,'%s'%(layer[lIdx]['l_name'])) gave me SyntaxError: ('invalid syntax',

Shai
  • 111,146
  • 38
  • 238
  • 371
batuman
  • 7,066
  • 26
  • 107
  • 229

1 Answers1

0

Look at this answer using __getitem__, or this answer using setattr:

n[layer[lIdx]['l_name']] = L.Convolution( # ...

or

setattr(n, layer[lIdx]['l_name'], L.Convolution( # ...

Python's join works on strings and produces strings, net.conv1_1 is not a string: it's conv1_1 attribute of object net.

Shai
  • 111,146
  • 38
  • 238
  • 371