我正在阅读神经转移pytorch教程,并对使用retain_variable(弃用,现在称为retain_graph)感到困惑.代码示例显示:
class ContentLoss(nn.Module):
def __init__(self, target, weight):
super(ContentLoss, self).__init__()
self.target = target.detach() * weight
self.weight = weight
self.criterion = nn.MSELoss()
def forward(self, input):
self.loss = self.criterion(input * self.weight, self.target)
self.output = input
return self.output
def backward(self, retain_variables=True):
#Why is retain_variables True??
self.loss.backward(retain_variables=retain_variables)
return self.loss
Run Code Online (Sandbox Code Playgroud)
从文档中
retain_graph(bool,optional) - 如果为False,将释放用于计算grad的图形.请注意,几乎在所有情况下都不需要将此选项设置为True,并且通常可以以更有效的方式解决此问题.默认为create_graph的值.
因此,通过设置retain_graph= True,我们不会释放在向后传递上为图形分配的内存.保持这种记忆的优势是什么,我们为什么需要它?
automatic-differentiation backpropagation neural-network conv-neural-network pytorch
我正在完成"Haskell中的并行和并发编程"的第3章,它有以下使用策略并行运行fibonacci序列的示例:
import Control.Parallel
import Control.Parallel.Strategies (rpar, Strategy, using)
import Text.Printf
import System.Environment
-- <<fib
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
-- >>
main = print pair
where
pair =
-- <<pair
(fib 35, fib 36) `using` parPair
-- >>
-- <<parPair
parPair :: Strategy (a,b)
parPair (a,b) = do
a' <- rpar a
b' <- rpar b
return (a',b')
-- >>
Run Code Online (Sandbox Code Playgroud)
当我编译它时:
ghc …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用docker和elastic beanstalk部署我的应用程序.我的Dockerrun.aws.json文件看起来像
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "jvans/maven_weekly",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "5000"
}],
"Volumes": [
{
"HostDirectory": "/Users/jamesvanneman/Code/maven_weekly/maven_weekly",
"ContainerDirectory": "/maven_weekly"
}
],
"Logging": "/var/log/nginx"
}
Run Code Online (Sandbox Code Playgroud)
我创建了这个应用程序,eb create当我运行时,eb deploy我得到了
Docker container quit unexpectedly after launch: Docker container quit
unexpectedly on Mon Sep 21 01:15:12 UTC 2015:. Check snapshot logs for details.
Hook /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
Run Code Online (Sandbox Code Playgroud)
在var/log/eb-activity.log我看到以下错误:
Docker container quit unexpectedly after …Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services docker amazon-elastic-beanstalk
我最近拆分了一个我拥有的rails应用程序,并创建了前端作为一个单独的应用程序与自耕农.由于某些原因,我的视图不再呈现,例如我的应用程序定义:
'use strict';
var actionTrackApp = angular.module('actionTrackApp', [ 'ui.router', 'ngGrid']);
actionTrackApp.config(function($locationProvider) {
return $locationProvider.html5Mode(true);
});
actionTrackApp.config(function($stateProvider){
$stateProvider
.state("packageIndex", {
url: "/packages",
views: {
"main": {
controller: "ApplicationCtrl",
template: "<h1>Test</h1>"
},
"": {
template: "<h1>Test2</h1>"
}
},
resolve: {
test: function(){
console.log("test")
}
}
})
});
Run Code Online (Sandbox Code Playgroud)
在我的index.html文件中,我有:
bodytag ng-app="actionTrackApp" ng-controller="ApplicationCtrl">
your site or application content here<a href='/packages'>Package Index</a>
<div ng-view="main" class="container"></div>
<div ng-view=""></div>
/bodytag
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,resolve属性确实解析了,我在控制台中看到"test".我尝试在应用程序控制器上附加$ routeChangeStart/success watch,但这里没有启动/成功.
我已经阅读了https://www.haskell.org/haskellwiki/Foldl_as_foldr和其他一些关于foldl和foldr之间区别的博客文章.现在我正在尝试将斐波那契序列作为带有折叠器的无限列表编写,我想出了以下解决方案:
fibs2 :: [Integer]
fibs2 = foldr buildFibs [] [1..]
where
buildFibs :: Integer -> [Integer] -> [Integer]
buildFibs _ [] = [0]
buildFibs _ [0] = [1,0]
buildFibs _ l@(x:s:z) = (x + s):l
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时take 3 fibs2,函数不会返回.我认为折叠是身体递归允许你在这些类型的情况下使用无限列表.为什么这不适合我的解决方案?