parameters: (layer)
return_statement: return tensors
docstring: (caffe.LayerParameter or caffe.V1LayerParameter) => anakin graph_io.TensorProtoIO
docstring_summary: (caffe.LayerParameter or caffe.V1LayerParameter) => anakin graph_io.TensorProtoIO
docstring_tokens: ( caffe . LayerParameter or caffe . V1LayerParameter ) = > anakin graph_io . TensorProtoIO
function: def GetTensorsFromCaffeLayer(layer):
      """(caffe.LayerParameter or caffe.V1LayerParameter) => anakin graph_io.TensorProtoIO
      """
      # filler blob first
      if layer.type == 'PReLU':
          if layer.prelu_param.HasField('filler') \
                  and layer.blobs[0].num == 0 \
                  and layer.prelu_param.channel_shared:
              # 1. filler only when layer.blobs[0] empty(layer.blobs[0].num == 0)
              # 2. PReLU must filler a [1, 1, 1, 1, ] blob
              layer.blobs[0].shape.dim[:] = [1, 1, 1, 1,]
              (layer.blobs[0].num,
                  layer.blobs[0].channels,
                  layer.blobs[0].height,
                  layer.blobs[0].width) = layer.blobs[0].shape.dim 
              layer.blobs[0].data[:] = [.0, ]
              layer.blobs[0].CopyFrom(
                  FillerCaffeBlob(layer.prelu_param.filler, layer.blobs[0]))
  
      # layer.blobs => tensors
      tensors = []
      for blob in layer.blobs:
          tensor = graph_io.TensorProtoIO()
          if len(blob.shape.dim):
              n, c, h, w = map(int, [1] * (4 - len(blob.shape.dim)) + list(blob.shape.dim))
              if len(blob.shape.dim) == 1:
                  c = w
                  w = 1
          else:
              n, c, h, w = blob.num, blob.channels, blob.height, blob.width
          tensor.set_data_type(graph_io.FLOAT) # default float
          if layer.type == "Deconvolution": # deconv is different in caffe
              tensor.set_shape([c, n, h, w])
          else:
              tensor.set_shape([n, c, h, w]) # set shape (n c h w)
          tensor.set_data(blob.data, "float")
          tensors.append(tensor)
  
      return tensors
function_tokens: def GetTensorsFromCaffeLayer ( layer ) : # filler blob first if layer . type == 'PReLU' : if layer . prelu_param . HasField ( 'filler' ) and layer . blobs [ 0 ] . num == 0 and layer . prelu_param . channel_shared : # 1. filler only when layer.blobs[0] empty(layer.blobs[0].num == 0) # 2. PReLU must filler a [1, 1, 1, 1, ] blob layer . blobs [ 0 ] . shape . dim [ : ] = [ 1 , 1 , 1 , 1 , ] ( layer . blobs [ 0 ] . num , layer . blobs [ 0 ] . channels , layer . blobs [ 0 ] . height , layer . blobs [ 0 ] . width ) = layer . blobs [ 0 ] . shape . dim layer . blobs [ 0 ] . data [ : ] = [ .0 , ] layer . blobs [ 0 ] . CopyFrom ( FillerCaffeBlob ( layer . prelu_param . filler , layer . blobs [ 0 ] ) ) # layer.blobs => tensors tensors = [ ] for blob in layer . blobs : tensor = graph_io . TensorProtoIO ( ) if len ( blob . shape . dim ) : n , c , h , w = map ( int , [ 1 ] * ( 4 - len ( blob . shape . dim ) ) + list ( blob . shape . dim ) ) if len ( blob . shape . dim ) == 1 : c = w w = 1 else : n , c , h , w = blob . num , blob . channels , blob . height , blob . width tensor . set_data_type ( graph_io . FLOAT ) # default float if layer . type == "Deconvolution" : # deconv is different in caffe tensor . set_shape ( [ c , n , h , w ] ) else : tensor . set_shape ( [ n , c , h , w ] ) # set shape (n c h w) tensor . set_data ( blob . data , "float" ) tensors . append ( tensor ) return tensors