小编mol*_*ilo的帖子

使用Librosa绘制Mel频谱图

我在使用声音的自定义文件路径在librosa中创建梅尔频谱图时遇到问题。

我正在遵循此文档:https : //librosa.github.io/librosa/generated/librosa.feature.melspectrogram.html

我看过这个堆栈溢出文章: 使用Librosa生成的频谱图看起来与Kaldi不一致?

但是,这些都没有帮助我解决问题。

import librosa
y, sr = librosa.load("path_to_my_wav_file")
librosa.feature.melspectrogram(y=y, sr=sr)
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 4))
librosa.display.specshow(librosa.power_to_db(y,                                              
ref=np.max), y_axis='mel', fmax=8000, x_axis='time')
plt.colorbar(format='%+2.0f dB')
plt.title('Mel spectrogram')
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何修复此代码,以使其正确显示并将mel-spectrogram保存为jpg文件吗?谢谢!

python spectrogram librosa

3
推荐指数
1
解决办法
7679
查看次数

访问 google colab 上的文件

通过运行安装驱动器后,我正在使用 Google Colaboratory IPython 进行样式转换:

from google.colab import drive
drive.mount('/drive')
Run Code Online (Sandbox Code Playgroud)

它已挂载,所以我尝试 cd 进入一个目录,显示密码和 ls 但它没有显示正确的密码

!cd "/content/drive/My Drive/"
!pwd
!ls
Run Code Online (Sandbox Code Playgroud)

但它不会 cd 到给定的目录中,它只会 cd 到 'content/'

同样,当我尝试在我的代码中使用“load_image() 函数访问一些图像时,如下所示

def load_image(img_path, max_size=400, Shape=None):
    image = Image.open(img_path).convert('RGB')
    if max(image.size) > max_size:
        size = max_size
    else:
        size = max(image.size)

    if shape is not None:
        size = shape

    in_transform = transforms.Compose([transforms.Resize(size),
                    transforms.ToTensor(),
                    transforms.Normalize((0.485, 0.456, 0.406), 
                                         (0.229, 0.224, 0.225))])

    image = in_transform(image)[:3,:,:].unsqueeze(0)

    return image
#load image content
content = load_image('content/drive/My Drive/uche.jpg')
style = load_image('content/drive/My Drive/uche.jpg') …
Run Code Online (Sandbox Code Playgroud)

conv-neural-network style-transfer google-colaboratory

3
推荐指数
1
解决办法
5623
查看次数

SGDClassifier 类的数量必须大于 1;上了1节课

因此,我已尽一切可能来解决这个错误,这也是我巨大的挫败感。

from sklearn.linear_model import SGDClassifier

train_labels_9 = [(label == 9) for label in train_labels_9]
test_labels_9 = [(label == 9) for label in test_labels_9]

sgd = SGDClassifier(max_iter = 1000, tol = 1e-3)
sgd.fit(train_images,train_labels_9)

below is the error
ValueError                                Traceback (most recent call last)
<ipython-input-57-8ad0fdf39a29> in <module>
      6 
      7 sgd = SGDClassifier(max_iter = 1000, tol = 1e-3)
----> 8 sgd.fit(train_images,train_labels_9)

~\Anaconda3\lib\site-packages\sklearn\linear_model\stochastic_gradient.py in fit(self, X, y, coef_init, intercept_init, sample_weight)
    741                          loss=self.loss, learning_rate=self.learning_rate,
    742                          coef_init=coef_init, intercept_init=intercept_init,
--> 743                          sample_weight=sample_weight)
    744 
    745 

~\Anaconda3\lib\site-packages\sklearn\linear_model\stochastic_gradient.py in _fit(self, …
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
3166
查看次数

我怎样才能在反向传播中获取softmax输出的导数

因此,我对 ML 很陌生,并尝试创建一个简单的“库”,以便我可以了解有关神经网络的更多信息。

我的问题:根据我的理解,我必须根据每层的激活函数求导数,这样我就可以计算它们的增量并调整它们的权重等......

对于 ReLU、sigmoid、tanh,用 Java 实现它们非常简单(顺便说一句,这是我使用的语言)

但要从输出到输入,我必须从(显然)具有 softmax 激活函数的输出开始。

那么我是否也必须采用输出层的导数,或者它只适用于所有其他层?

如果我确实必须获得导数,我怎样才能在Java中实现导数呢?谢谢。

我已经阅读了很多关于 Softmax 算法导数的解释的页面,但它们对我来说真的很复杂,正如我所说,我刚刚开始学习 ML,我不想使用现成的库,所以在这里我是。

这是我存储激活函数的类。

public class ActivationFunction {

    public static double tanh(double val) {
        return Math.tanh(val);
    }

    public static double sigmoid(double val) {
        return 1 / 1 + Math.exp(-val);
    }

    public static double relu(double val) {
        return Math.max(val, 0);
    }

    public static double leaky_relu(double val) {
        double result = 0;
        if (val > 0) result = val;
        else result = val * 0.01;
        return result;
    } …
Run Code Online (Sandbox Code Playgroud)

java machine-learning derivative backpropagation softmax

3
推荐指数
1
解决办法
5297
查看次数

运行时错误:mat1和mat2形状无法在pytorch中相乘

我是深度学习的新手,我使用下面的代码创建了一个模型来预测植物病害

class CNN_Model(nn.Module):
  def __init__(self):
    super(CNN_Model, self).__init__()
    self.cnn_model = nn.Sequential(
        nn.Conv2d(3, 16, 3),    
        nn.ReLU(),
        nn.MaxPool2d(2, 2),     
        nn.Conv2d(16, 32, 5),   
        nn.ReLU(),
        nn.MaxPool2d(2, 2),     
    )

    self.fc_model = nn.Sequential(
        nn.Flatten(),           
        nn.Linear(800, 300),    
        nn.ReLU(),
        nn.Linear(300, 38),     
        nn.Softmax(dim=1)
    )

  def forward(self, x):
      x = self.cnn_model(x)
      x = self.fc_model(x)

      return x
Run Code Online (Sandbox Code Playgroud)
model = CNN_Model()

out = model(imgs)
out
Run Code Online (Sandbox Code Playgroud)

当我尝试运行上面的代码时,出现错误 mat1 和 mat2 无法相乘。我已经尝试过针对类似问题发布的答案,但我的问题仍然没有解决。

RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_66/1768380315.py in <module>
----> 1 out = model(imgs)
      2 out

/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1049         if …
Run Code Online (Sandbox Code Playgroud)

python artificial-intelligence deep-learning pytorch

3
推荐指数
1
解决办法
4万
查看次数

librosa 错误 -&gt; AttributeError: 模块“librosa.display”没有属性“waveplot”

错误的SS:

我尝试使用这段代码:

!pip install --upgrade librosa
Run Code Online (Sandbox Code Playgroud)

但它仍然给我同样的错误。我该如何解决这个问题,有人可以帮助我吗?

python librosa

3
推荐指数
1
解决办法
2591
查看次数

我可以同时对测试数据和训练数据使用 CountVectorizer 还是需要将其分开?

我目前有一个 SVM 模型,可以将文本分为两个不同的类别。我目前正在使用 CountVectorizer 和 TfidfTransformer 来创建我的“词向量”。

问题是,当我首先转换所有文本然后将其拆分时,我认为我可能以错误的顺序进行操作。

我的问题是,如果我先执行train_test_split,然后仅对训练数据执行fit_transform,然后对测试数据进行转换,会有什么区别吗?

正确的做法是什么?

非常感谢,祝您编码愉快!

count_vect = CountVectorizer(stop_words='english')
X_counts = count_vect.fit_transform(textList)

tfidf_transformer = TfidfTransformer()
X_tfidf = tfidf_transformer.fit_transform(X_counts)

X_train, X_test, y_train, y_test = train_test_split(X_tfidf, correctLabels, test_size=.33, random_state=17)
Run Code Online (Sandbox Code Playgroud)

machine-learning word-count scikit-learn text-classification

2
推荐指数
1
解决办法
3642
查看次数

需要构建自定义 NER 以从任何格式的工资单中提取以下关键字的方法

我正在尝试从任何格式的工资单中构建以下参数的通用提取:

  1. 姓名
  2. 他的邮政编码
  3. 发薪日
  4. 净支付。

我面临的挑战是由于可能出现的各种格式,我想应用 NER (Spacy) 在实体下学习这些

  1. 姓名 - 人
  2. 他的邮政编码
  3. 付款日期 - 日期
  4. 净支付。- 钱

但是到目前为止我没有成功,我什至尝试为 Postcode & Date 构建自定义 EntityMatcher 但没有成功。

我寻求任何指导方针和方法,使我采取正确的道路来实现上述问题,在 ML 下实现这一目标的正确和最佳方法是什么。

我尝试构建的自定义 NER 片段

import spacy
import random
import threading
import time
from DateEntityMatcher import  DateEntityMatcher
from PostCodeEntityMatcher import PostCodeEntityMatcher


class IncomeValidatorModel(object):
    """ Threading example class
    The run() method will be started and it will run in the background
    until the application exits.
    """

    def __init__(self, interval=1):
        """ Constructor
        :type interval: int
        :param …
Run Code Online (Sandbox Code Playgroud)

nlp python-3.x spacy ner

2
推荐指数
1
解决办法
340
查看次数

无论聚类中心如何初始化,Kmeans 算法是否都能保证收敛?为什么?

K-means 是一种随机初始化聚类中心的迭代算法。无论聚类中心如何初始化,Kmeans 算法是否都能保证收敛?为什么?

artificial-intelligence machine-learning k-means unsupervised-learning data-science

2
推荐指数
1
解决办法
3653
查看次数

如何在 python 3.12.1 上安装 PyTorch

我正在安装 DARTS TimeSeries 库(https://github.com/unit8co/darts/blob/master/INSTALL.md#enabling-optical-dependencies),但遇到了依赖项安装问题。在 DARTS 安装指南中,它说如果我们遇到这个问题,我们必须参考 PyTorch 的官方安装指南,然后尝试再次安装 Darts。然后,当我尝试在 python 3.12.1 上安装 torch 时,我遇到了这个错误:

\n
\n

错误:找不到满足火炬要求的版本(来自版本:无)

\n

错误:找不到火炬的匹配发行版。

\n
\n

怎么解决呢?

\n

我使用 PyCharm 作为 Python 代码编辑器。

\n

我尝试了pip install darts,但它没有安装所有软件包并遇到此错误 error: subprocess-exited-with-error

\n
  pip subprocess to install build dependencies did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [136 lines of output]\n      Collecting setuptools>=64.0\n        Obtaining dependency information for setuptools>=64.0 from https://files.pythonhosted.org/packages\n
Run Code Online (Sandbox Code Playgroud)\n

然后,我尝试使用 pip install torch 来安装 torch 并遇到此错误\n错误:找不到满足需求 torch 的版本(来自版本:无)\n错误:找不到 torch 的匹配发行版

\n

python machine-learning torch

1
推荐指数
1
解决办法
638
查看次数

将字符串作为指针传递时出错,无法将const char *分配给char *

我正在从一本教科书中学习C ++(《 C ++:初学者指南》,第二版,Herbert Schildt)。以下程序代码摘自本书,但错误,请有人向我解释为什么不允许这样做吗?

目的是演示一个指针作为参数:

#include <iostream>

using namespace std;

char *get_substr(char *sub, char *str); //function prototype

int main()
{
    char *substr;
    substr = get_substr("three", "one two three four");

    cout << "substring found: " << substr;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我不会列出函数体,因为它按预期运行,但是即使它仅返回零,也会导致以下错误:类型为“ const char *”的E0167参数与类型为“ char *”的参数不兼容,引用函数调用。我的理解是,无论如何,字符串基本上是C中char的数组,为什么不允许这样做,什么是合适的替代方法?先感谢您。

c++ string pointers char

0
推荐指数
1
解决办法
97
查看次数

动态创建作为默认函数参数传递的派生类对象的最佳和最安全的方法是什么?

我有一堂课

class Base {
public:
    virtual ~Base() {}
    virtual string returnString() = 0;
};

class B : public A {
public:
     string returnString() { return "string"; }
}

class C : public A {
public:
     string returnString() { return ""; }
}
Run Code Online (Sandbox Code Playgroud)

和功能

string returnStringFunction(...);
Run Code Online (Sandbox Code Playgroud)

我希望能够传递 C 类型的对象,但默认情况下,我希望此函数使用动态创建的 B 类型对象。

我记得使用过这样的东西:

string returnStringFunction(const A& a = *std::make_unique<B>()) 
Run Code Online (Sandbox Code Playgroud)

或者

string returnStringFunction(const std::unique_ptr<A> a = std::make_unique<B>()) 
Run Code Online (Sandbox Code Playgroud)

函数体示例:

string returnStringFunction(...) {
    return a->returnString();
}
Run Code Online (Sandbox Code Playgroud)

但是这两个解决方案即使它们通常在我的“沙盒”环境中编译和工作,它们也会在工作区上生成SIGFAULT。知道是什么原因造成的或如何更好地解决它吗?

提前致谢

c++ smart-pointers default-arguments

-1
推荐指数
1
解决办法
68
查看次数

如何在 Graphcore IPU 中使用 tensorflow

我想用 graphcore IPU 测试性能,但我不知道如何使用 tensorflow。有人可以帮我做到这一点吗?

python artificial-intelligence tensorflow ipu

-3
推荐指数
1
解决办法
374
查看次数