为了尝试简化这个问题,我已经定义了这些箭头函数:
splitA :: (Arrow arr) => arr a b -> arr a (b,a)
splitA ar = ar &&& (arr (\a -> id a))
recordArrow
:: (Arrow arr)
=> (d -> r)
-> (d -> r -> d)
-> (r -> r)
-> arr d d
recordArrow g s f = splitA (arr g >>^ f) >>^ \(r,d) -> s d r
Run Code Online (Sandbox Code Playgroud)
然后让我做这样的事情:
unarrow :: ((->) b c) -> (b -> c) -- unneeded as pointed out to me in the …Run Code Online (Sandbox Code Playgroud) 我有两个网络:一个Model生成输出,一个Adversary对输出进行分级.
两者都经过单独培训,但现在我需要在单个会话期间将它们的输出结合起来.
我试图实现这篇文章中提出的解决方案:同时运行多个预先训练的Tensorflow网络
我的代码
with tf.name_scope("model"):
model = Model(args)
with tf.name_scope("adv"):
adversary = Adversary(adv_args)
#...
with tf.Session() as sess:
tf.global_variables_initializer().run()
# Get the variables specific to the `Model`
# Also strip out the surperfluous ":0" for some reason not saved in the checkpoint
model_varlist = {v.name.lstrip("model/")[:-2]: v
for v in tf.global_variables() if v.name[:5] == "model"}
model_saver = tf.train.Saver(var_list=model_varlist)
model_ckpt = tf.train.get_checkpoint_state(args.save_dir)
model_saver.restore(sess, model_ckpt.model_checkpoint_path)
# Get the variables specific to the `Adversary`
adv_varlist = {v.name.lstrip("avd/")[:-2]: v …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用分析来诊断程序中的无限循环。因为我必须使用 Ctrl-C 中止程序,所以 .prof 文件仍为空。据我所知,如果程序崩溃,.prof 文件应该仍然可以工作。
为了测试这是否是我的特定程序的配置,我写了这样的:
module Main (
main
) where
testInf = map (+1) [1..]
main = do
print (show testInf)
Run Code Online (Sandbox Code Playgroud)
我正在使用 Leksah,配置生成以下 .cabal 文件:
name: tests
version: 0.0.1
cabal-version: >=1.2
build-type: Simple
license: AllRightsReserved
license-file: ""
description:
data-dir: ""
executable tests
build-depends: base -any
main-is: Main.hs
buildable: True
hs-source-dirs: src
ghc-options: -prof -auto-all
Run Code Online (Sandbox Code Playgroud)
然后我通过运行来执行该程序tests +RTS -p。当我使用 Crl-C 终止程序时,.prof 文件为 0kb。如果我更改程序,使其不会无限运行,它会在完成后生成完整的 .prof 文件。
其他详情
using version 1.16.0 of the Cabal libraryGlasgow Haskell …我最近开始使用Sublime Text进行编码.这引起了我的注意,当我使用Leksah时,我没有注意到一些警告.所以我得到了这个:
import qualified Data.Set as S
Run Code Online (Sandbox Code Playgroud)
得到:
Warning:
The qualified import of `Data.Set' is redundant
except perhaps to import instances from `Data.Set'
To import instances alone, use: import Data.Set()
Run Code Online (Sandbox Code Playgroud)
另一方面,这两个进口中的Data.Foldable任何一个都没有发出任何警告:
import Data.Foldable (foldrM, mapM_,foldr,foldl',concat)
-- or
import Data.Foldable
Run Code Online (Sandbox Code Playgroud)
所以我不确定Data.Set的警告意味着什么.我希望"多余"意味着它没有必要.如果我删除导入它不会编译,因为我正在为Data.Set使用很多东西.
同时坐在它旁边import qualified Data.Map as M也没有发出警告.
所以我对这个警告所说的完全感到困惑.
如果可以为以下情况编写抽象,我正在尝试解决问题.假设我有一个a带有函数的类型,a -> m Bool例如MVar Bool和readMVar.为了抽象出这个概念,我为类型及其函数创建了一个newtype包装器:
newtype MPredicate m a = MPredicate (a,a -> m Bool)
Run Code Online (Sandbox Code Playgroud)
我可以像这样定义一个相当简单的操作:
doUnless :: (Monad m) => Predicate m a -> m () -> m ()
doUnless (MPredicate (a,mg)) g = mg a >>= \b -> unless b g
main = do
b <- newMVar False
let mpred = MPredicate (b,readMVar)
doUnless mpred (print "foo")
Run Code Online (Sandbox Code Playgroud)
在这种情况下doUnless会打印"foo".旁白:我不确定类型类是否更适合使用而不是newtype.
现在取下面的代码,输出一个递增的数字,然后等待一秒钟并重复.这样做直到它通过MVar收到"关闭"指令.
foobar :: MVar Bool -> IO ()
foobar …Run Code Online (Sandbox Code Playgroud)