sharathadavanne / sed-crnn

Single and multichannel sound event detection using convolutional recurrent neural networks. DCASE 2017 real-life sound event detection winning method.
Other
184 stars 46 forks source link

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' #12

Open arshinmar opened 3 years ago

arshinmar commented 3 years ago

Hello,

I would like to begin by saying thank you for publishing this code and results.

I am trying to reproduce the results from the code, but am running into some code issues.

To give some context, I am trying to reproduce the results with tensorflow-gpu==2.1.3. Therefore, I slightly changed the import section (shown below) of sed.py due to compatibility errors between Tensorflow 1 and 2.

from __future__ import print_function
import os
import numpy as np
import time
import sys
import matplotlib.pyplot as plot
from tensorflow.keras.layers import Bidirectional, TimeDistributed, Conv2D, MaxPooling2D, Input, GRU, Dense, Activation, Dropout, Reshape, Permute, BatchNormalization
from tensorflow.keras.models import Model
from sklearn.metrics import confusion_matrix
import metrics
import utils
from IPython import embed
import tensorflow.keras.backend as K
K.set_image_data_format('channels_first')
plot.switch_backend('agg')
sys.setrecursionlimit(10000)

However, once I run the new code, it triggers the following error.

UNIQUE ID: bin_2021_05_25_17_48_56
TRAINING PARAMETERS: nb_ch: 2, seq_len: 256, batch_size: 128, nb_epoch: 500, frames_1_sec: 43
MODEL PARAMETERS:
 cnn_nb_filt: 128, cnn_pool_size: [5, 2, 2], rnn_nb: [32, 32], fc_nb: [32], dropout_rate: 0.5

----------------------------------------------
FOLD: 1
----------------------------------------------

Traceback (most recent call last):
  File "sed.py", line 139, in <module>
    model = get_model(X, Y, cnn_nb_filt, cnn_pool_size, rnn_nb, fc_nb)
  File "sed.py", line 41, in get_model
    merge_mode='mul')(spec_x)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/wrappers.py", line 543, in __call__
    return super(Bidirectional, self).__call__(inputs, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 748, in __call__
    self._maybe_build(inputs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2116, in _maybe_build
    self.build(input_shapes)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/wrappers.py", line 697, in build
    self.forward_layer.build(input_shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/recurrent_v2.py", line 372, in build
    super(GRU, self).build(input_shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/recurrent.py", line 564, in build
    self.cell.build(step_input_shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/utils/tf_utils.py", line 306, in wrapper
    output_shape = fn(instance, input_shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/recurrent.py", line 1741, in build
    caching_device=default_caching_device)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 446, in add_weight
    caching_device=caching_device)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 744, in _add_variable_with_custom_getter
    **kwargs_for_getter)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer_utils.py", line 142, in make_variable
    shape=variable_shape if variable_shape else None)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/variables.py", line 258, in __call__
    return cls._variable_v1_call(*args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/variables.py", line 219, in _variable_v1_call
    shape=shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/variables.py", line 197, in <lambda>
    previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/variable_scope.py", line 2596, in default_variable_creator
    shape=shape)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/variables.py", line 262, in __call__
    return super(VariableMetaclass, cls).__call__(*args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 1411, in __init__
    distribute_strategy=distribute_strategy)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 1542, in _init_from_args
    initial_value() if init_from_fn else initial_value,
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer_utils.py", line 122, in <lambda>
    init_val = lambda: initializer(shape, dtype=dtype)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/init_ops_v2.py", line 415, in __call__
    scale /= max(1., (fan_in + fan_out) / 2.)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

This error may have been caused by the difference in tensorflow-gpu version. It would be much appreciated if you could recommend the tensorflow version to use or if any other error is causing this issue.

Thanks!

sharathadavanne commented 3 years ago

Hi @arshinmar thanks for using this repo. I have tested this code with Keras 2.2.4 and Tensorflow 1.14.0, which is basically one of the preconfigured TensorFlow environments in my university. I have been planning to update these scripts to Tensorflow2, haven't gotten to do it yet. Looking forward to your implementation of it. Also, I don't have any comments on the error you have been getting.