【发布时间】:2021-05-09 17:30:34
【问题描述】:
我通过混合正负对来制作成对的图像。这个过程计算量很大,需要大量的 RAM 和处理器。为了加快速度,我想使用 GPU 并将熊猫代码更改为 CUDF。现在,CUDF的文档非常有限,我想把下面的代码改成CUDF。
positives = pd.DataFrame()
for value in tqdm(identities.values(), desc="Positives"):
positives = positives.append(pd.DataFrame(itertools.combinations(value, 2), columns=["file_x", "file_y"]),
ignore_index=True)
positives["decision"] = "Yes"
print(positives)
samples_list = list(identities.values())
negatives = pd.DataFrame()
######################====================Functions=============##############
def compute_cross_samples(x):
return pd.DataFrame(itertools.product(*x), columns=["file_x", "file_y"])
####################################
if __name__ == "__main__":
if Path("positives_negatives.csv").exists():
df = pd.read_csv("positives_negatives.csv")
else:
with ProcessPoolExecutor() as pool:
# take cpu_count combinations from identities.values
for combos in tqdm(more_itertools.ichunked(itertools.combinations(identities.values(), 2), cpu_count())):
# for each combination iterator that comes out, calculate the cross
for cross_samples in pool.map(compute_cross_samples, combos):
# for each product iterator "cross_samples", iterate over its values and append them to negatives
negatives = negatives.append(cross_samples)
negatives["decision"] = "No"
negatives = negatives.sample(positives.shape[0])
df = pd.concat([positives, negatives]).reset_index(drop=True)
df.to_csv("positives_negatives.csv", index=False)`
【问题讨论】:
-
多处理池不适用于 CUDA。 cudf 数组有一个从 pandas 转换的方法。
-
没问题,你可以删除多处理代码我只想在 GPU 上运行代码。多处理需要 9 天然后给出错误。在过去的两个月里,我面临着这个问题。需要帮助
-
您的确切问题是什么?
-
我必须构建一个非常大的列表并且创建列表的时间很多。我必须通过 GPU 利用率来最小化它。
-
如果您创建一个最小的、完整的、可重现的示例,社区可能会更好地帮助您。 stackoverflow.com/help/minimal-reproducible-example
标签: python python-3.x pandas numpy cudf