質問編集履歴
3
一部パラメータをダミーに
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,113 +1,114 @@
|
|
|
1
|
-
### 前提・実現したいこと
|
|
2
|
-
numpyのlistをnp.save()によって保存をしたい。
|
|
3
|
-
|
|
4
|
-
### 発生している問題・エラーメッセージ
|
|
5
|
-
|
|
6
|
-
---------------------------------------------------------------------------
|
|
7
|
-
ValueError Traceback (most recent call last)
|
|
8
|
-
<ipython-input-1-1775b596e8ba> in <module>()
|
|
9
|
-
60
|
|
10
|
-
61 filename = 'x.npy'
|
|
11
|
-
---> 62 np.save(filename, audio)
|
|
12
|
-
63 filename_2='y.npy'
|
|
13
|
-
64 np.save(filename_2,label)
|
|
14
|
-
|
|
15
|
-
~\Anaconda3\lib\site-packages\numpy\lib\npyio.py in save(file, arr, allow_pickle, fix_imports)
|
|
16
|
-
517
|
|
17
|
-
518 try:
|
|
18
|
-
--> 519 arr = np.asanyarray(arr)
|
|
19
|
-
520 format.write_array(fid, arr, allow_pickle=allow_pickle,
|
|
20
|
-
521 pickle_kwargs=pickle_kwargs)
|
|
21
|
-
|
|
22
|
-
~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asanyarray(a, dtype, order)
|
|
23
|
-
551
|
|
24
|
-
552 """
|
|
25
|
-
--> 553 return array(a, dtype, copy=False, order=order, subok=True)
|
|
26
|
-
554
|
|
27
|
-
555
|
|
28
|
-
|
|
29
|
-
ValueError: could not broadcast input array from shape (20,883) into shape (20)
|
|
30
|
-
#コード
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#print(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
#print(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
print(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
### 前提・実現したいこと
|
|
2
|
+
numpyのlistをnp.save()によって保存をしたい。
|
|
3
|
+
|
|
4
|
+
### 発生している問題・エラーメッセージ
|
|
5
|
+
|
|
6
|
+
---------------------------------------------------------------------------
|
|
7
|
+
ValueError Traceback (most recent call last)
|
|
8
|
+
<ipython-input-1-1775b596e8ba> in <module>()
|
|
9
|
+
60
|
|
10
|
+
61 filename = 'x.npy'
|
|
11
|
+
---> 62 np.save(filename, audio)
|
|
12
|
+
63 filename_2='y.npy'
|
|
13
|
+
64 np.save(filename_2,label)
|
|
14
|
+
|
|
15
|
+
~\Anaconda3\lib\site-packages\numpy\lib\npyio.py in save(file, arr, allow_pickle, fix_imports)
|
|
16
|
+
517
|
|
17
|
+
518 try:
|
|
18
|
+
--> 519 arr = np.asanyarray(arr)
|
|
19
|
+
520 format.write_array(fid, arr, allow_pickle=allow_pickle,
|
|
20
|
+
521 pickle_kwargs=pickle_kwargs)
|
|
21
|
+
|
|
22
|
+
~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asanyarray(a, dtype, order)
|
|
23
|
+
551
|
|
24
|
+
552 """
|
|
25
|
+
--> 553 return array(a, dtype, copy=False, order=order, subok=True)
|
|
26
|
+
554
|
|
27
|
+
555
|
|
28
|
+
|
|
29
|
+
ValueError: could not broadcast input array from shape (20,883) into shape (20)
|
|
30
|
+
#コード
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
import librosa
|
|
36
|
+
import os
|
|
37
|
+
import numpy as np
|
|
38
|
+
|
|
39
|
+
audio=[]
|
|
40
|
+
label=[]
|
|
41
|
+
name=[]
|
|
42
|
+
|
|
43
|
+
path='./'
|
|
44
|
+
X=os.path.join(path,'X')
|
|
45
|
+
Xl = os.listdir(X)
|
|
46
|
+
Y=os.path.join(path,'Y')
|
|
47
|
+
Yl = os.listdir(Y)
|
|
48
|
+
Z = os.path.join(path,'Z')
|
|
49
|
+
Zl= os.listdir(Z)
|
|
50
|
+
|
|
51
|
+
max = 0
|
|
52
|
+
print("start")
|
|
53
|
+
for aud in Xl:
|
|
54
|
+
apath = os.path.join(X,aud)
|
|
55
|
+
x,fs = librosa.load(apath,sr=44100)
|
|
56
|
+
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
57
|
+
#print (mfccs.shape)
|
|
58
|
+
#print(type(mfccs))
|
|
59
|
+
audio.append(mfccs)
|
|
60
|
+
if(max<mfccs.shape[1]):
|
|
61
|
+
max = mfccs.shape[1]
|
|
62
|
+
la = 0
|
|
63
|
+
label.append(la)
|
|
64
|
+
name.append(aud)
|
|
65
|
+
#print(type(audio))
|
|
66
|
+
|
|
67
|
+
print("33%")
|
|
68
|
+
for aud in Zl:
|
|
69
|
+
apath = os.path.join(Z,aud)
|
|
70
|
+
x,fs = librosa.load(apath,sr=44100)
|
|
71
|
+
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
72
|
+
#print (mfccs.shape)
|
|
73
|
+
#print(type(mfccs))
|
|
74
|
+
audio.append(mfccs)
|
|
75
|
+
if(max<mfccs.shape[1]):
|
|
76
|
+
max = mfccs.shape[1]
|
|
77
|
+
la = 1
|
|
78
|
+
label.append(la)
|
|
79
|
+
name.append(aud)
|
|
80
|
+
|
|
81
|
+
print("66%")
|
|
82
|
+
for aud in Yl:
|
|
83
|
+
apath = os.path.join(Y,aud)
|
|
84
|
+
x,fs = librosa.load(apath,sr=44100)
|
|
85
|
+
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
86
|
+
# print (mfccs.shape)
|
|
87
|
+
#print(type(mfccs))
|
|
88
|
+
audio.append(mfccs)
|
|
89
|
+
if(max<mfccs.shape[1]):
|
|
90
|
+
max = mfccs.shape[1]
|
|
91
|
+
la = 2
|
|
92
|
+
label.append(la)
|
|
93
|
+
name.append(aud)
|
|
94
|
+
|
|
95
|
+
filename = 'x.npy'
|
|
96
|
+
np.save(filename, audio)
|
|
97
|
+
filename_2='y.npy'
|
|
98
|
+
np.save(filename_2,label)
|
|
99
|
+
filename_3='fn.npy'
|
|
100
|
+
np.save(filename_3,name)
|
|
101
|
+
|
|
102
|
+
print(max)
|
|
103
|
+
print("finish")
|
|
104
|
+
|
|
105
|
+
```Python
|
|
106
|
+
### 試したこと
|
|
107
|
+
|
|
108
|
+
ファイルネームの拡張子を.npzに変えたりしました。
|
|
109
|
+
audio はnp.darrayのlist 次元数は2です。
|
|
110
|
+
label は整数のlist
|
|
111
|
+
filename は元ファイルのパスを保存しているlistであることをtype()によって確認しました。
|
|
112
|
+
|
|
113
|
+
### 補足情報(FW/ツールのバージョンなど)
|
|
113
114
|
自作で音声データセットを作ろうと試みています。librosaというライブラリを使い各音声データの特徴量(numpy.darray)とラベルとファイルネームをそれぞれ冒頭で定義したlistに保存し、np.save()によって保存を試みましたが、上記の様なエラーが出てしまい保存をすることができません。エラーメッセージからブロードキャストの問題というのはわかるのですが、解決方法がわかりません。
|
2
追加修正」
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
### 試したこと
|
|
106
106
|
|
|
107
107
|
ファイルネームの拡張子を.npzに変えたりしました。
|
|
108
|
-
audio はnp.darrayのlist
|
|
108
|
+
audio はnp.darrayのlist 次元数は2です。
|
|
109
109
|
label は整数のlist
|
|
110
110
|
filename は元ファイルのパスを保存しているlistであることをtype()によって確認しました。
|
|
111
111
|
|
1
コードのインデントを修正しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -27,13 +27,10 @@
|
|
|
27
27
|
555
|
|
28
28
|
|
|
29
29
|
ValueError: could not broadcast input array from shape (20,883) into shape (20)
|
|
30
|
-
|
|
30
|
+
#コード
|
|
31
|
+
|
|
31
32
|
```
|
|
32
33
|
|
|
33
|
-
### 該当のソースコード
|
|
34
|
-
|
|
35
|
-
Python
|
|
36
|
-
ソースコード
|
|
37
34
|
import librosa
|
|
38
35
|
import os
|
|
39
36
|
import numpy as np
|
|
@@ -56,21 +53,23 @@
|
|
|
56
53
|
apath = os.path.join(angry,aud)
|
|
57
54
|
x,fs = librosa.load(apath,sr=44100)
|
|
58
55
|
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
59
|
-
|
|
56
|
+
#print (mfccs.shape)
|
|
57
|
+
#print(type(mfccs))
|
|
60
58
|
audio.append(mfccs)
|
|
61
59
|
if(max<mfccs.shape[1]):
|
|
62
60
|
max = mfccs.shape[1]
|
|
63
61
|
la = 0
|
|
64
62
|
label.append(la)
|
|
65
63
|
name.append(aud)
|
|
66
|
-
|
|
64
|
+
#print(type(audio))
|
|
67
65
|
|
|
68
66
|
print("33%")
|
|
69
67
|
for aud in normall:
|
|
70
68
|
apath = os.path.join(normal,aud)
|
|
71
69
|
x,fs = librosa.load(apath,sr=44100)
|
|
72
70
|
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
73
|
-
|
|
71
|
+
#print (mfccs.shape)
|
|
72
|
+
#print(type(mfccs))
|
|
74
73
|
audio.append(mfccs)
|
|
75
74
|
if(max<mfccs.shape[1]):
|
|
76
75
|
max = mfccs.shape[1]
|
|
@@ -83,6 +82,8 @@
|
|
|
83
82
|
apath = os.path.join(happy,aud)
|
|
84
83
|
x,fs = librosa.load(apath,sr=44100)
|
|
85
84
|
mfccs= librosa.feature.mfcc(x,sr=fs)
|
|
85
|
+
# print (mfccs.shape)
|
|
86
|
+
#print(type(mfccs))
|
|
86
87
|
audio.append(mfccs)
|
|
87
88
|
if(max<mfccs.shape[1]):
|
|
88
89
|
max = mfccs.shape[1]
|
|
@@ -100,6 +101,7 @@
|
|
|
100
101
|
print(max)
|
|
101
102
|
print("finish")
|
|
102
103
|
|
|
104
|
+
```Python
|
|
103
105
|
### 試したこと
|
|
104
106
|
|
|
105
107
|
ファイルネームの拡張子を.npzに変えたりしました。
|