Skip to content

Commit fce8746

Browse files
[fix] Fix TypeError: numpy.float64 cannot be interpreted as integer (#716)
Cast encoder.n_feats_out and similar values to int across all model constructors to prevent TypeError when numpy returns float64 scalars from arithmetic operations. Newer numpy versions enforce stricter integer type checking, causing nn.Conv1d, nn.Parameter, and other PyTorch layers to reject numpy.float64 where a Python int is expected. Fixes #713
1 parent 76b485f commit fce8746

11 files changed

Lines changed: 14 additions & 13 deletions

File tree

asteroid/masknn/recurrent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def __init__(self, encoders, decoders, n_freqs, **kwargs):
676676
super().__init__(
677677
encoders=[
678678
*(DCUNetComplexEncoderBlock(*args, activation="prelu") for args in encoders),
679-
DCCRMaskNetRNN(np.prod(last_encoder_out_shape)),
679+
DCCRMaskNetRNN(int(np.prod(last_encoder_out_shape))),
680680
],
681681
decoders=[
682682
torch.nn.Identity(),

asteroid/models/conv_tasnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
sample_rate=sample_rate,
7777
**fb_kwargs,
7878
)
79-
n_feats = encoder.n_feats_out
79+
n_feats = int(encoder.n_feats_out)
8080
if in_chan is not None:
8181
assert in_chan == n_feats, (
8282
"Number of filterbank output channels"

asteroid/models/dccrnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DCCRNet(BaseDCUNet):
2424
def __init__(
2525
self, *args, stft_n_filters=512, stft_kernel_size=400, stft_stride=100, **masknet_kwargs
2626
):
27-
masknet_kwargs.setdefault("n_freqs", stft_n_filters // 2)
27+
masknet_kwargs.setdefault("n_freqs", int(stft_n_filters) // 2)
2828
super().__init__(
2929
*args,
3030
stft_n_filters=stft_n_filters,

asteroid/models/demask.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def __init__(
6161
**fb_kwargs,
6262
)
6363

64-
n_masker_in = self._get_n_feats_input(input_type, encoder.n_feats_out)
65-
n_masker_out = self._get_n_feats_output(output_type, encoder.n_feats_out)
64+
n_feats_out = int(encoder.n_feats_out)
65+
n_masker_in = self._get_n_feats_input(input_type, n_feats_out)
66+
n_masker_out = self._get_n_feats_output(output_type, n_feats_out)
6667
masker = build_demask_masker(
6768
n_masker_in,
6869
n_masker_out,

asteroid/models/dprnn_tasnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
sample_rate=sample_rate,
8383
**fb_kwargs,
8484
)
85-
n_feats = encoder.n_feats_out
85+
n_feats = int(encoder.n_feats_out)
8686
if in_chan is not None:
8787
assert in_chan == n_feats, (
8888
"Number of filterbank output channels"

asteroid/models/dptnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(
7979
sample_rate=sample_rate,
8080
**fb_kwargs,
8181
)
82-
n_feats = encoder.n_feats_out
82+
n_feats = int(encoder.n_feats_out)
8383
if in_chan is not None:
8484
assert in_chan == n_feats, (
8585
"Number of filterbank output channels"

asteroid/models/lstm_tasnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
sample_rate=sample_rate,
6969
**fb_kwargs,
7070
)
71-
n_feats = encoder.n_feats_out
71+
n_feats = int(encoder.n_feats_out)
7272
if in_chan is not None:
7373
assert in_chan == n_feats, (
7474
"Number of filterbank output channels"

asteroid/models/sudormrf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(
6262
output_padding=(kernel_size // 2) - 1,
6363
**fb_kwargs,
6464
)
65-
n_feats = enc.n_feats_out
65+
n_feats = int(enc.n_feats_out)
6666
enc = _Padder(enc, upsampling_depth=upsampling_depth, kernel_size=kernel_size)
6767

6868
if in_chan is not None:
@@ -136,7 +136,7 @@ def __init__(
136136
output_padding=(kernel_size // 2) - 1,
137137
**fb_kwargs,
138138
)
139-
n_feats = enc.n_feats_out
139+
n_feats = int(enc.n_feats_out)
140140
enc = _Padder(enc, upsampling_depth=upsampling_depth, kernel_size=kernel_size)
141141

142142
if in_chan is not None:

asteroid/models/x_umx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
self.nb_channels = nb_channels
7474
self.nb_layers = nb_layers
7575
self.bidirectional = bidirectional
76-
self.nb_output_bins = in_chan // 2 + 1
76+
self.nb_output_bins = int(in_chan) // 2 + 1
7777
if max_bin:
7878
self.max_bin = max_bin
7979
else:

egs/dns_challenge_INTERSPEECH2020/baseline/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def make_model_and_optimizer(conf):
2828
# Because we concatenate (re, im, mag) as input and compute a complex mask.
2929
if conf["main_args"]["is_complex"]:
3030
inp_size = int(stft.n_feats_out * 3 / 2)
31-
output_size = stft.n_feats_out
31+
output_size = int(stft.n_feats_out)
3232
else:
3333
inp_size = output_size = int(stft.n_feats_out / 2)
3434
# Add these fields to the mask model dict

0 commit comments

Comments
 (0)