Tutorial-SoftWeightSharingForNNCompression icon indicating copy to clipboard operation
Tutorial-SoftWeightSharingForNNCompression copied to clipboard

error: ZeroDivisionError: integer division or modulo by zero

Open guolinke opened this issue 8 years ago • 1 comments

I fork this and adapt to the Keras 2.0. (https://github.com/guolinke/Tutorial-SoftWeightSharingForNNCompression) But it shows an error when running (the retrain part):

import optimizers 
from extended_keras import identity_objective

tau = 0.003
N = X_train.shape[0] 

opt = optimizers.Adam(lr = [5e-4,1e-4,3e-3,3e-3],  #[unnamed, means, log(precition), log(mixing proportions)]
                      param_types_dict = ['means','gammas','rhos'])

model.compile(optimizer = opt,
              loss = {"error_loss": "categorical_crossentropy", "complexity_loss": identity_objective},
              loss_weights = {"error_loss": 1. , "complexity_loss": tau/N},
              metrics = ['accuracy'])

error log:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/training.py", line 953, in compile
    append_metric(i, 'acc', masked_fn(y_true, y_pred, mask=masks[i]))
  File "/anaconda/envs/py35/lib/python3.5/site-packages/keras/engine/training.py", line 479, in masked
    score_array = fn(y_true, y_pred)
  File "/anaconda/envs/py35/lib/python3.5/site-packages/keras/metrics.py", line 25, in categorical_accuracy
    K.argmax(y_pred, axis=-1)),
  File "/anaconda/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1198, in argmax
    axis = _normalize_axis(axis, ndim(x))
  File "/anaconda/envs/py35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 991, in _normalize_axis
    axis %= ndim
ZeroDivisionError: integer division or modulo by zero

guolinke avatar Jul 22 '17 10:07 guolinke

@guolinke I met the same problem. Have you solved it?

IdiosyncraticDragon avatar Apr 14 '18 07:04 IdiosyncraticDragon