Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples/mnist_net2net.py type of list keys was float #9324

Merged
merged 1 commit into from
Feb 8, 2018

Conversation

gorogoroyasu
Copy link
Contributor

I tried to run examples/mnist_net2net.py and I got an error in my env.
The error is similer to this thread and I fixed it.

error occured

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-2-c38539c7e5b8> in <module>()
    385 # run the experiments
    386 net2wider_experiment()
--> 387 net2deeper_experiment()

<ipython-input-2-c38539c7e5b8> in net2deeper_experiment()
    375                               x_test, y_test,
    376                               init='net2deeper',
--> 377                               epochs=epochs)
    378 
    379 

<ipython-input-2-c38539c7e5b8> in make_deeper_student_model(teacher_model, x_train, y_train, x_test, y_test, init, epochs)
    301     if init == 'net2deeper':
    302         prev_w, _ = model.get_layer('conv2').get_weights()
--> 303         new_weights = deeper2net_conv2d(prev_w)
    304         model.add(Conv2D(64, 3, padding='same',
    305                          name='conv2-deeper', weights=new_weights))

<ipython-input-2-c38539c7e5b8> in deeper2net_conv2d(teacher_w)
    196     student_w = np.zeros_like(teacher_w)
    197     for i in range(filters):
--> 198         student_w[(kh - 1) / 2, (kw - 1) / 2, i, i] = 1.
    199     student_b = np.zeros(filters)
    200     return student_w, student_b

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

my environment

# python -V
Python 3.6.2
# pip freeze | grep Keras
Keras==2.0.9
# pip freeze | grep numpy
numpy==1.13.3

In my env, the error shown below occured, and it would be fixed by this change.  
The error is similer to [this thread](https://stackoverflow.com/questions/34952651/only-integers-slices-ellipsis-numpy-newaxis-none-and-intege) and I fixed it.

## error occured
```
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-2-c38539c7e5b8> in <module>()
    385 # run the experiments
    386 net2wider_experiment()
--> 387 net2deeper_experiment()

<ipython-input-2-c38539c7e5b8> in net2deeper_experiment()
    375                               x_test, y_test,
    376                               init='net2deeper',
--> 377                               epochs=epochs)
    378 
    379 

<ipython-input-2-c38539c7e5b8> in make_deeper_student_model(teacher_model, x_train, y_train, x_test, y_test, init, epochs)
    301     if init == 'net2deeper':
    302         prev_w, _ = model.get_layer('conv2').get_weights()
--> 303         new_weights = deeper2net_conv2d(prev_w)
    304         model.add(Conv2D(64, 3, padding='same',
    305                          name='conv2-deeper', weights=new_weights))

<ipython-input-2-c38539c7e5b8> in deeper2net_conv2d(teacher_w)
    196     student_w = np.zeros_like(teacher_w)
    197     for i in range(filters):
--> 198         student_w[(kh - 1) / 2, (kw - 1) / 2, i, i] = 1.
    199     student_b = np.zeros(filters)
    200     return student_w, student_b

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
```

## my environment
```
# python -V
Python 3.6.2
# pip freeze | grep Keras
Keras==2.0.9
# pip freeze | grep numpy
numpy==1.13.3
```
@gorogoroyasu gorogoroyasu changed the title The type of list keys was float Fix examples/mnist_net2net.py type of list keys was float Feb 7, 2018
@elephantgrass7
Copy link

LGTM not sure why your environ only keras 2.0.9

@fchollet fchollet merged commit 4c79e3e into keras-team:master Feb 8, 2018
@gorogoroyasu gorogoroyasu deleted the patch-1 branch February 9, 2018 01:54
ahundt added a commit to ahundt/keras that referenced this pull request Feb 16, 2018
* 'master' of github.com:fchollet/keras: (57 commits)
  Minor README edit
  Speed up Travis tests (keras-team#9386)
  fix typo (keras-team#9391)
  Fix style issue in docstring
  Prepare 2.1.4 release.
  Fix activity regularizer + model composition test
  Corrected copyright years (keras-team#9375)
  Change default interpolation from nearest to bilinear. (keras-team#8849)
  a capsule cnn on cifar-10 (keras-team#9193)
  Enable us to use sklearn to do cv for functional api (keras-team#9320)
  Add support for stateful metrics. (keras-team#9253)
  The type of list keys was float (keras-team#9324)
  Fix mnist sklearn wrapper example (keras-team#9317)
  keras-team#9287 Fix most of the file-handle resource leaks. (keras-team#9309)
  Pass current learning rate to schedule() in LearningRateScheduler (keras-team#8865)
  Simplify with from six.moves import input (keras-team#9216)
  fixed RemoteMonitor: Json to handle np.float32 and np.int32 types (keras-team#9261)
  Update tweet length from 140 to 280 in docs
  Add `depthconv_conv2d` tests (keras-team#9225)
  Remove `force` option in progbar
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants