所以我想将频谱图图像提供给卷积神经网络,以尝试对各种声音进行分类。我希望每个图像都是 384x128 像素。但是,当我实际保存图像时,它只有 297x98。这是我的代码:
def save_spectrogram(num):
dpi = 128
x_pixels = 384
y_pixels = 128
samples, sr = load_wave(num)
stft = np.absolute(librosa.stft(samples))
db = librosa.amplitude_to_db(stft, ref=np.max)
fig = plt.figure(figsize=(x_pixels//dpi, y_pixels//dpi), dpi=dpi, frameon=False)
ax = fig.add_subplot(111)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_frame_on(False)
librosa.display.specshow(db, y_axis='linear')
plt.savefig(TRAIN_IMG+str(num)+'.jpg', bbox_inches='tight', pad_inches=0, dpi=dpi)
Run Code Online (Sandbox Code Playgroud)
有没有人对我如何解决这个问题有任何指示?我也试过在没有子图的情况下这样做,但是当我这样做时,它仍然保存为错误的大小并且有空白/背景。
我想使用filesystem现在属于 C++17 标准的新库,但是我无法编译。
我已经尝试过的事情:
g++ -std=c++17 test.cpp -o test-lstdc++fs到编译(这不起作用,我收到错误c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lstdc++fs)<filesystem>以及<experimental\filesystem>这是我的简单测试代码,只是为了尝试编译:
#include <iostream>
#include <filesystem>
using namespace std;
int main(int argc, char* argv[]) {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并编译 g++ -std=c++17 test.cpp -o test
有了这个,我得到了错误:
In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\filesystem:37,
from test.cpp:2:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() …Run Code Online (Sandbox Code Playgroud)