-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
System information
- OS Platform and Distribution: Linux Ubuntu 18.04
- Python version: 3.6.9
- NumPy version: 1.19.5
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.
numpy-ml/numpy_ml/neural_nets/initializers/initializers.py
Lines 176 to 194 in b537fac
| def init_from_dict(self): | |
| O = self.param | |
| cc = O["cache"] if "cache" in O else None | |
| op = O["hyperparameters"] if "hyperparameters" in O else None | |
| if op is None: | |
| raise ValueError("Must have `hyperparemeters` key: {}".format(O)) | |
| if op and op["id"] == "SGD": | |
| optimizer = SGD().set_params(op, cc) | |
| elif op and op["id"] == "RMSProp": | |
| optimizer = RMSProp().set_params(op, cc) | |
| elif op and op["id"] == "AdaGrad": | |
| optimizer = AdaGrad().set_params(op, cc) | |
| elif op and op["id"] == "Adam": | |
| optimizer = Adam().set_params(op, cc) | |
| elif op: | |
| raise NotImplementedError("{}".format(op["id"])) | |
| return optimizer |
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.hyperparametersThis raises AttributeError: 'NoneType' object has no attribute 'cache'.
The same happens with Scheduler.