ddbourgin / numpy-ml

Machine learning, in numpy
https://numpy-ml.readthedocs.io/
GNU General Public License v3.0
15.26k stars 3.7k forks source link

Bug in initializers init_from_dict() #63

Closed RaulMurillo closed 3 years ago

RaulMurillo commented 3 years ago

System information

Describe the current behavior When calling the init_from_dict() method from numpy_ml/neural_nets/initializers, from both SchedulerInitializer and OptimizerInitializer classes, the returned object is None, rather than a propper object. This is caused by the assignation of the set_params() method to the returned object. Such a method does not return an object but modifies the instance itself. https://github.com/ddbourgin/numpy-ml/blob/b537fac970f85d4919fe8c491499480a3a71bf8c/numpy_ml/neural_nets/initializers/initializers.py#L176-L194

Describe the expected behavior init_from_dict() should return a propper object that will be assigned to an attribute of a NN layer.

Code to reproduce the issue

from numpy_ml.neural_nets.layers import *

c1 = Conv2D(6, (3,3))
opt = c1.hyperparameters['optimizer'] # dict

c2=Conv2D(6, (3,3), optimizer=opt) # The optimizer is set to None
c2.hyperparameters

This raises AttributeError: 'NoneType' object has no attribute 'cache'. The same happens with Scheduler.