在 pytorch 中,如果我没有写任何关于使用 CPU/GPU 的内容,并且我的机器支持 CUDA ( torch.cuda.is_available() == True):
torch.cuda.is_available() == False吗?我正在写这样的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.你想弄明白这个问题吗?非常感谢! …
我试着写这段代码
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是正常的,但正确的索引已被线程破坏.
我也尝试过在互联网和这里提供的一些方法(使用并行用于外部循环并使用关键进行最终比较)但这会导致速度下降而不是加速.
我该怎么做才能使最小值及其索引正确?谢谢!
这些说法正确吗?
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) >>> 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作为该库的功能?
此代码在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)