Skip to content

Bug in transfer learning #61

@RaulMurillo

Description

@RaulMurillo

System information

  • OS Platform and Distribution: Linux Ubuntu 18.04
  • Python version: 3.6.9
  • NumPy version: 1.19.5

Describe the current behavior
There is a problem when trying to perform simple transfer learning techniques (loading the same parameters from another trained layers/models).
When setting layer params with a layer summary dictionary (generated with the summary() method), the activation function can be overridden with a string due to the non-exclusive if-clauses:

if k in self.hyperparameters:
if k == "act_fn":
layer.act_fn = ActivationInitializer(v)()
if k == "optimizer":
layer.optimizer = OptimizerInitializer(sd[k])()
if k not in ["wrappers", "optimizer"]:
setattr(layer, k, v)
if k == "wrappers":
layer = init_wrappers(layer, sd[k])

This causes an error when trying to call the layer activation function in the forward() method.

Describe the expected behavior
Layers that get their parameters with the set_params() method should behave without errors.

Code to reproduce the issue

>>> import numpy as np
>>> from numpy_ml.neural_nets.layers import *
>>>
>>> c1 = Conv2D(6, (3,3))
>>> c2 = Conv2D(6, (3,3))
>>> x = np.random.randn(1, 32, 32, 3)
>>>
>>> y1 = c1.forward(x)
>>> y2 = c2.forward(x) # No problem here
>>>
>>> c2.set_params(c1.summary()) # The act_fn of c2 is overridden as a str
<numpy_ml.neural_nets.layers.layers.Conv2D object at 0x7f0bf9d405f8>
>>> y3 = c2.forward(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ramuri01/numpy-ml/numpy_ml/neural_nets/layers/layers.py", line 2822, in forward
    Y = self.act_fn(Z)
TypeError: 'str' object is not callable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions