小编Kha*_*lam的帖子

pandas ValueError:无法在具有新类别的类别上设置项目,请先设置类别

现在,我正在更改 DataFrame 内的信息,将 Yes 替换为 1,No 替换为 0。以前,我的代码工作正常,现在由于内存问题我做了一些更改。

以前的代码“出现下面提到的回溯错误”

df.loc[df[df.decision == 'Yes'].index, 'decision'] = 1
df.loc[df[df.decision == 'No'].index, 'decision'] = 0
Run Code Online (Sandbox Code Playgroud)

更改为

df.loc['Yes', "decision"] = 1
df.loc['No', "decision"] = 0
Run Code Online (Sandbox Code Playgroud)

尽管如此,问题仍然是一样的。

追溯

Traceback (most recent call last):
  File "/snap/pycharm-community/226/plugins/python-ce/helpers/pydev/pydevd.py", line 1477, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/snap/pycharm-community/226/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/khawar/deepface/tests/Ensemble-Face-Recognition.py", line 148, in <module>
    df.loc['Yes', "decision"] = 1
  File "/home/khawar/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 670, in __setitem__
    iloc._setitem_with_indexer(indexer, value) …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

进程完成,退出代码 137(被信号 9 中断:SIGKILL):检索图像数据

我从人脸图像中提取特征,然后使用不同的相似性度量将特征与其他图像进行比较。以前,图像名称列表很小,但工作正常。代表每个图像的整个列表我将这些列表放入 json 文件中并在 python 文件中使用。当我增加图像时,PyCharm 会终止我的进程。

import pandas as pd
import numpy as np
import itertools
from sklearn import metrics
from sklearn.metrics import confusion_matrix, accuracy_score, roc_curve, auc
import matplotlib.pyplot as plt
import json
from tqdm import tqdm
from sklearn.utils.multiclass import type_of_target

import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf

tf.compat.v1.disable_eager_execution()

with open('/home/khawar/deepface/tests/ageDB.json') as f:
    data = json.load(f)

idendities = data

# --------------------------
# Data set

# Ref: https://github.com/serengil/deepface/tree/master/tests/dataset

# --------------------------
# Positives

positives = []

for key, values in …
Run Code Online (Sandbox Code Playgroud)

python numpy pycharm pandas

6
推荐指数
0
解决办法
4593
查看次数

python列表中的内存泄漏问题

身份列表包含大约57000 张图像的大数组。现在,我正在借助itertools.product(). 这将整个列表存储在内存中,这非常昂贵,并且我的系统在 4 分钟后挂起。

如何优化以下代码并避免节省内存?`

for i in range(0, len(idendities) - 1):
    for j in range(i + 1, len(idendities)):
        cross_product = itertools.product(samples_list[i], samples_list[j])
        cross_product = list(cross_product)

        for cross_sample in cross_product:
            negative = []
            negative.append(cross_sample[0])
            negative.append(cross_sample[1])
            negatives.append(negative)
            print(len(negatives))

negatives = pd.DataFrame(negatives, columns=["file_x", "file_y"])
negatives["decision"] = "No"

negatives = negatives.sample(positives.shape[0])
Run Code Online (Sandbox Code Playgroud)

内存9.30会越来越高,有一点系统已经完全挂了。

我还根据他的回答实现了以下答案并修改了代码。

for i in range(0, len(idendities) - 1):
    for j in range(i + 1, len(idendities)):
        for cross_sample in itertools.product(samples_list[i], samples_list[j]):
            negative = [cross_sample[0], cross_sample[1]]
            negatives.append(negative)
            print(len(negatives)) …
Run Code Online (Sandbox Code Playgroud)

python optimization product list python-itertools

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

torch.no_grad() 影响模型精度

我收到错误“CUDA 内存不足”,然后我将 torch.no_grad() 函数添加到我的代码中。这会影响我的准确性吗?

for iters in range(args.iterations):

with torch.no_grad():
    encoded, encoder_h_1, encoder_h_2, encoder_h_3 = encoder(
    res, encoder_h_1, encoder_h_2, encoder_h_3)

with torch.no_grad():
    code = binarizer(encoded)

with torch.no_grad():
    output, decoder_h_1, decoder_h_2, decoder_h_3, decoder_h_4 = decoder(
    code, decoder_h_1, decoder_h_2, decoder_h_3, decoder_h_4)

res = res - output.detach()
codes.append(code.data.cpu().numpy())
torch.cuda.empty_cache()
print('Iter: {:02d}; Loss: {:.06f}'.format(iters, res.data.abs().mean()))
Run Code Online (Sandbox Code Playgroud)

python model image-compression torch pytorch

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

ValueError:不支持未知格式:ROC 曲线

我刚刚将 python 版本从 3.5 更新到 3.7,在构建 ROC 曲线时出现错误。我没有更改代码中的任何内容,但它给出了一些未知错误

代码

# ROC Curve

from sklearn.metrics import confusion_matrix, accuracy_score, roc_auc_score, roc_curve
y_pred_proba = predictions[::, 1]
print("y_pred_proba", y_pred_proba)
print("y_test", y_test)

fpr, tpr, _ = roc_curve(y_test, y_pred_proba)
auc = roc_auc_score(y_test, y_pred_proba)

plt.figure(figsize=(7, 3))
Run Code Online (Sandbox Code Playgroud)

价值观

y_pred_proba [0.1746994 0.22792926 0.60020134 0.60857445 0.38630289 0.16318228 0.20503542 0.76781874 0.89951127 0.13657112 0.36836385 0.23833946 0.43924601 0.9874083 0.98404103 0.1003149 0.94596688 0.36480605 0.48716601 0.04158647 0.8624937 0.93881636 0.54065999 0.38538261 0.48002784 0.9874083 0.76781874 0.95791353 0.48002784 0.2448756 0.98404103 0.06473023 0.34080482 0.11897602 0.07883822 0.08000581 0.38630289 0.2546955 0.95515939 …

python numpy python-3.x pandas scikit-learn

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