小编xxb*_*iao的帖子

如果我没有指定使用 CPU/GPU,那么我的脚本使用的是哪一个?

在 pytorch 中,如果我没有写任何关于使用 CPU/GPU 的内容,并且我的机器支持 CUDA ( torch.cuda.is_available() == True):

  1. 我的脚本使用的是 CPU 还是 GPU?
  2. 如果是 CPU,我应该怎么做才能让它在 GPU 上运行?我需要重写所有内容吗?
  3. 如果是 GPU,这个脚本会崩溃torch.cuda.is_available() == False吗?
  4. 这对加快训练速度有帮助吗?
  5. 我知道将PyTorch 代码从 CPU 移植到 GPU,但这是旧的。这种情况会在 v0.4 或即将到来的 v1.0 中改变吗?

python pytorch

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

Dllmain没被调用?

我正在写这样的dllmain:

#include "main.h"
#include "init.h"
#include <iostream>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
//std::cout<<"hi\n"; //only for debug. did not shown.
switch (fdwReason)
{
    case DLL_PROCESS_ATTACH:
        // attach to process
        // return FALSE to fail DLL load
        //std::cout<<"hello\n"; //only for debug. did not shown.
        init(); //did not run :(
        break;

    case DLL_PROCESS_DETACH:
        // detach from process
        break;

    case DLL_THREAD_ATTACH:
        // attach to thread
        break;

    case DLL_THREAD_DETACH:
        // detach from thread
        break;
}
return TRUE; // succesful
}
Run Code Online (Sandbox Code Playgroud)

但是在测试程序使用LoadLibrary()之后,屏幕上没有任何事情发生,没有hello或hi.你想弄明白这个问题吗?非常感谢! …

c++

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

使用openMP并行获取最小元素的索引

我试着写这段代码

float* theArray; // the array to find the minimum value
int   index, i;
float thisValue, min;

index    = 0;
min = theArray[0];
#pragma omp parallel for reduction(min:min_dist)
for (i=1; i<size; i++) {
    thisValue = theArray[i];
    if (thisValue < min)

    { /* find the min and its array index */

        min = thisValue;

        index    = i;
    }
}
return(index);
Run Code Online (Sandbox Code Playgroud)

然而,这个没有输出正确的答案.似乎min是正常的,但正确的索引已被线程破坏.

我也尝试过在互联网和这里提供的一些方法(使用并行用于外部循环并使用关键进行最终比较)但这会导致速度下降而不是加速.

我该怎么做才能使最小值及其索引正确?谢谢!

c++ openmp

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

Model.trainable = False 与 Model.compile()

这些说法正确吗?

  • Model.trainable = False 除非编译发生,否则它本身绝对没有影响(对任何编译的东西)。
  • 如果我取ModelA已编译的两层( ModelA.compile(...)),创建一个跳过模型ModelB=Model(intermediate_layer1, intermediate_layer2)并设置ModelB.trainable=False, ModelB.compile(...),则不会有任何变化ModelA;假设 trainable 没有被触及,ModelA如果只训练 ModelA ,那么所有的权重都会更新 ( ModelA.fit(...))
  • 这仅适用于重量更新,因此重量将被保存/加载而不会出现问题(即使它是错误的重量)。

这一切都始于我尝试训练 GAN 时,在训练生成器时冻结鉴别器并收到此警告:

 UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?
Run Code Online (Sandbox Code Playgroud)

我调查了这个,发现人们也调查了这个:

https://github.com/keras-team/keras/issues/8585

这是改编自该问题线程的可重现示例:

# making discriminator
d_input = Input(shape=(2,))
d_output = Activation('softmax')(Dense(2)(d_input))
discriminator = Model(inputs=d_input, outputs=d_output)
discriminator.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['categorical_accuracy'])

# making generator
g_input = Input(shape=(2,))
g_output = Activation('relu')(Dense(2)(g_input)) …
Run Code Online (Sandbox Code Playgroud)

python keras

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

如果项目不可比较,heapq 无法处理具有相同优先级的元组

>>> from heapq import heappush
>>> heap = []
>>> heappush(heap,(0,{"k":0}))
>>> heappush(heap,(0,{"k":1}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'dict' and 'dict'
Run Code Online (Sandbox Code Playgroud)

python2和 python3的官方 heapq 文档中提到了这一点,该文档建议使用 DIY 实现来缓解此问题。heapq

为什么会发生这种情况?heapq鉴于这是一个非常旧的库,这种冲突没有得到解决的根本原因是什么?是否有性能/其他问题?为什么我们不能只提供参数keep_old, keep_any作为该库的功能?

python heapq

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

升级到tensorflow v1.0后,使用tensorflow.mul()的代码失败

此代码在Tensorflow v0.12.1上运行,但在TF v1.0上的新安装上失败.是不是这个功能被弃用了?我应该使用什么功能?(Tensorflow启动并运行所以我认为这不是一个错误的配置)

  File "***.py", line 115, in trainNetwork
    readout_action = tf.reduce_sum(tf.mul(readout, a), reduction_indices = 1)
AttributeError: module 'tensorflow' has no attribute 'mul'
Run Code Online (Sandbox Code Playgroud)

python tensorflow

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

标签 统计

python ×4

c++ ×2

heapq ×1

keras ×1

openmp ×1

pytorch ×1

tensorflow ×1