小编jam*_*mes的帖子

如何在python 3.8中安装opencv-python

我在 pycharm 中安装 opencv-python 时遇到问题。打开pycharm后,我点击设置,然后点击项目解释器,点击“+”并搜索正确的模块,我开始安装但失败了

Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python
Run Code Online (Sandbox Code Playgroud)

此外,我尝试通过控制台安装它,但出现相同的错误。我也更新到了最新的 pip 版本,我该如何解决这个问题?

python opencv python-3.x python-3.8

6
推荐指数
2
解决办法
2万
查看次数

张量板不显示验证集上的准确性和损失图

我是机器学习的新手,我正在尝试制作图像分类器,模型训练正确,但问题出在张量板上,如何可视化验证集上的损失和准确性图?你唯一看到的是测试集上的损失和准确性

model.compile(loss='categorical_crossentropy',
                                optimizer='adam',
                                metrics=['accuracy'])
model.fit(X, y, batch_size=32, epochs=5, validation_split=0.3, callbacks=[tensorboard])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python tensorflow tensorboard

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

在信号处理程序上调用 fprintf() 是否安全?

在我的程序中,我有这样的事情

#include "mylib.h"
void signalsHandler(int signum){
    switch(signum){
        case SIGUSR1:{
            //open file.txt with write(O_CREAT | O_APPEND)
            //call the function that use fprintf() and write on file.txt

        }
        default: {
            abort();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

主要是

struct sigaction s;
memset(&s,0,sizeof(s));
s.sa_handler=signalsHandler;
s.sa_flags=SA_RESTART;
sigaction(SIGUSR1,&s,NULL);
Run Code Online (Sandbox Code Playgroud)

在 mylib.h 上调用使用 fprintf() 写入文件的函数是否安全?根据这里我只能打电话写

c printf signals system-calls

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

在 python 中打开或创建文件并附加到它

你如何在Python中执行这一系列操作?

1)如果文件不存在则创建一个文件并插入字符串

2)如果文件存在,则查找是否包含字符串

3)如果字符串不存在,则挂在文件末尾

我目前正在这样做,但我错过了一步

每次我调用该函数时都使用此代码进行编辑似乎该文件不存在并覆盖旧文件

def func():
if not os.path.exists(path):
    #always take this branch
    with open(path, "w") as myfile:
        myfile.write(string)
        myfile.flush()
        myfile.close()
else:
    with open(path) as f:
        if string in f.read():
            print("string found")
        else:
            with open(path, "a") as f1:
                f1.write(string)
                f1.flush()
                f1.close()
    f.close()
Run Code Online (Sandbox Code Playgroud)

python file append

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

从python中的列表中删除元素并避免转移

我在python中有一个列表,每当元素满足特定条件时,我都会删除该元素。问题在于for循环似乎正在跳过某些元素。我认为这是因为删除后列表已移至左侧。那么如何正确删除列表中的项目呢?这是我的代码

list = [0, 0, 0, 1, 1, 0 ,0, 1, 0]

for elem in list:
    if elem == 0:
        list.remove(elem)

print(list)
Run Code Online (Sandbox Code Playgroud)

这就是结果 [1, 1, 0, 1, 0]

python list

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

错误“请求转换为非标量类型”

我正在尝试使用线程池并使用选择来实现多线程服务器,因此我已fd_set set全局声明我传递给线程池运行的函数。我收到此错误

在函数 'threadF' 转换为非标量类型请求 fd_set set1=(fd_set) s;

代码是这样的

pool *createPool(int size){
    /*...*/
    if((err=pthread_create(&id,NULL,&threadF,(void *)&set))!=0){
        fprintf(stderr,"thread\n");
        exit(errno);
    }
    /*...*/
}

void *threadF(void* s){
    fd_set set1=(fd_set) s;
    /*...*/
}
Run Code Online (Sandbox Code Playgroud)

也许我忘记了什么?

c select multithreading threadpool server

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

如何将 numpy 数组作为耳语模型的音频提供

所以我想使用 AudioSegment 打开 mp3,然后我想将 AudioSegment 对象转换为 numpy 数组并使用此 numpy 数组作为耳语模型的输入,我遵循了这个问题How to create a numpy array from a pydub AudioSegment? 但结果没有任何帮助,因为我总是遇到类似的错误

    Traceback (most recent call last):
  File "E:\Programmi\PythonProjects\whisper_real_time\test\converting_test.py", line 19, in <module>
    result = audio_model.transcribe(arr_copy, language="en", word_timestamps=True,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programmi\PythonProjects\whisper_real_time\venv\Lib\site-packages\whisper\transcribe.py", line 121, in transcribe
    mel = log_mel_spectrogram(audio, padding=N_SAMPLES)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programmi\PythonProjects\whisper_real_time\venv\Lib\site-packages\whisper\audio.py", line 146, in log_mel_spectrogram
    audio = F.pad(audio, (0, padding))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: [enforce fail at ..\c10\core\impl\alloc_cpu.cpp:72] data. DefaultCPUAllocator: not enough memory: you tried to allocate 86261939712 bytes.
Run Code Online (Sandbox Code Playgroud)

这个错误很奇怪,因为如果我直接提供如下文件,我就不会遇到任何问题

result = audio_model.transcribe("../audio_test_files/1001_IEO_DIS_HI.mp3", …
Run Code Online (Sandbox Code Playgroud)

python numpy audiosegment openai-whisper

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