探索FAKE,一个适用于所有.NET的F#构建系统

I've been orbiting around F# - but not really jumping in - for a while now. In fact, I looked at F# in 2008 almost 6 years ago and more recently talked to Richard Minerich and Phillip Trelford on Hanselminutes Podcast #311 "Why F#?"

我一直在绕F#轨道飞行-但现在还没有真正跳进去-已经有一段时间了。 实际上,我大约6年前的2008年看过F#,最近Hanselminutes Podcast#311 “为什么使用F#?”上Richard Minerich和Phillip Trelford进行了交谈

Last week I looked at using ScriptCS, literally C# as a Scripting language, to drive browser automation. Today I'm exploring a make system called FAKE. It's F# Make, a build automation system similar to Make (which is 38 years old next month!) or Rake (which uses Ruby).

上周,我研究了使用ScriptCS (实际上是C#作为脚本语言)来驱动浏览器自动化。 今天,我正在探索一个名为FAKE的make系统。 它是F#Make ,它是一个类似于Make(下个月已经38岁!)或Rake(使用Ruby)的构建自动化系统。

Fake is a Domain Specific Language that you can use without knowing F#, but if and when you outgrow it you can keep heading down the F# road. In all cases you've got all of .NET at your command.

Fake是一种特定于域的语言,您可以在不了解F#的情况下使用它,但是如果您不再使用它,则可以继续前进。 在所有情况下,您都可以使用所有.NET。

Here's their Hello World example, a basic deploy script:

这是他们的Hello World示例,一个基本的部署脚本:

#r "tools/FAKE/tools/FakeLib.dll" // include Fake lib
open Fake


Target "Test" (fun _ ->
trace "Testing stuff..."
)

Target "Deploy" (fun _ ->
trace "Deploy stuff..."
)

"Test" // define the dependencies
==> "Deploy"

Run "Deploy"

Note that Deploy depends on Test.

请注意,部署取决于测试。

FAKE uses F# but you can use it go build whatever. These are some C# OSS projects that use FAKE to build themselves:

FAKE使用F#,但是您可以使用它来构建任何东西。 以下是一些使用FAKE自己构建的C#OSS项目:

FAKE isn't new, it's actually been around for 4 years with 55 contributors so far! It works not only on .NET but also on Linux and Mac under Mono - it works everywhere. Because it's all .NET you can use it on your Continuous Integration Servers like TeamCity or Travis CI.

FAKE并不是什么新鲜事物,到目前为止,它已经有55位贡献者了4年了! 它不仅可以在.NET上运行,还可以在Mono下Linux和Mac上运行-随处都可以使用。 因为都是.NET,所以您可以在诸如TeamCityTravis CI之类的持续集成服务器上使用它。

image

FAKE入门 (Getting Started with FAKE)

Check out their Calculator sample, a .NET project you'll extend to build itself with FAKE. Just download the zip, unblock it, and unzip. Then run build.bat from a developer command prompt.

查看他们的Calculator示例,这是一个.NET项目,您将对其进行扩展以使用FAKE构建自身。 只需下载zip文件,然后将其解锁并解压缩。 然后从开发人员命令提示符运行build.bat。

The build.net is a bootstrapper. It could be powershell or a shell script if you like, of course.

build.net是一个引导程序。 当然,它可以是powershell或shell脚本。

@echo off
cls
"tools\nuget\nuget.exe" "install" "FAKE" "-OutputDirectory" "tools" "-ExcludeVersion"
"tools\FAKE\tools\Fake.exe" build.fsx
pause

This batch file uses NuGet to get FAKE, just as npm install restores node_modules, or gem gets ruby libraries. Then it calls Fake on the build.fsx file. Follow their Getting Started instructions to slowly expand the responsibilities of the build.fsx file.

这个批处理文件使用NuGet来获取FAKE,就像npm install恢复node_modules一样,或者gem获取ruby库一样。 然后,在build.fsx文件上调用Fake。 按照他们的入门指南逐步扩展build.fsx文件的职责。

FAKE has a lot of Helpers in their API documentation. Hundreds, and there's a whole community making others that you can call upon. For example, the built in FileHelper has things like CleanDir to remove files and subdirs.

FAKE在其API文档中有很多帮助程序。 数百个社区组成了您可以呼吁的其他社区。 例如,内置的FileHelper具有CleanDir之类的功能,可以删除文件和子目录。

Here we Clean before we build by making Clean a dependency of Default. BuildDir here is a property that's shared.

在这里,我们通过将Clean设置为Default的依赖项来进行清理。 BuildDir是共享的属性。

// include Fake lib
#r "tools/FAKE/tools/FakeLib.dll"
open Fake

// Properties
let buildDir = "./build/"

// Targets
Target "Clean" (fun _ ->
CleanDir buildDir
)

Target "Default" (fun _ ->
trace "Hello World from FAKE"
)

// Dependencies
"Clean"
==> "Default"

// start build
RunTargetOrDefault "Default"

Jumping to the end of the tutorial, the syntax gets a little more tricky, butu once you get the |> format, it makes sense.

跳到本教程的结尾,语法变得有些棘手,但是一旦获得|>格式,它就会变得有意义。

Some cool things to note and file away as interesting at in the script below.

在下面的脚本中,一些很有趣的事情要注意并归档,以免引起兴趣。

  • the use of !! to include files

    指某东西的用途 !! 包含文件
  • the use of -- to exclude a file spec after a !! operator

    使用-排除!!之后的文件规范算子
  • Zip is built-in as a helper and zips up the results of the build.

    Zip是作为帮助程序内置的,并压缩构建结果。
  • the options passed into NUnit

    传递给NUnit的选项
  • The dependency chain

    依赖链
  • #r for referencing .NET DLLs

    #r用于引用.NET DLL
// include Fake lib
#r "tools/FAKE/tools/FakeLib.dll"
open Fake

RestorePackages()

// Properties
let buildDir = "./build/"
let testDir = "./test/"
let deployDir = "./deploy/"

// version info
let version = "0.2" // or retrieve from CI server

// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir; deployDir]
)

Target "BuildApp" (fun _ ->
!! "src/app/**/*.csproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)

Target "BuildTest" (fun _ ->
!! "src/test/**/*.csproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)

Target "Test" (fun _ ->
!! (testDir + "/NUnit.Test.*.dll")
|> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = testDir + "TestResults.xml" })
)

Target "Zip" (fun _ ->
!! (buildDir + "/**/*.*")
-- "*.zip"
|> Zip buildDir (deployDir + "Calculator." + version + ".zip")
)

Target "Default" (fun _ ->
trace "Hello World from FAKE"
)

// Dependencies
"Clean"
==> "BuildApp"
==> "BuildTest"
==> "Test"
==> "Zip"
==> "Default"

// start build
RunTargetOrDefault "Default"

You can do virtually anything and there's a great community out there to help.

您几乎可以做任何事情,这里有一个很棒的社区可以提供帮助。

Here's a more complex dependency chain with an optional parameter:

这是带有可选参数的更复杂的依赖项链:

// Build order
"Clean"
==> "BuildApp"
==> "BuildTest"
==> "FxCop"
==> "NUnitTest"
=?> ("xUnitTest",hasBuildParam "xUnitTest") // runs the target only if FAKE was called with parameter xUnitTest
==> "Deploy"

There's a rich FAKE world out there with support for Octopus Deploy, all Unit Test systems, Xamarin's xpkg format and much more. Thanks to Steffan Forkmann for helping me explore this. ;)

支持章鱼部署,所有单元测试系统,Xamarin的xpkg格式以及更多其他功能,有一个丰富的FAKE世界。 感谢Steffan Forkmann帮助我探索这一点。 ;)

相关链接 (Related Links)

翻译自: https://www.hanselman.com/blog/exploring-fake-an-f-build-system-for-all-of-net

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对抗神经网络可以用于图像去模糊的任务,其中的基本思路是通过训练一个生成器网络来生成清晰的图像,同时训练一个判别器网络来区分清晰图像和模糊图像。 以下是一个简单的基于对抗神经网络的图像去模糊代码示例: ```python import tensorflow as tf import numpy as np import cv2 # 加载数据 blurry_image = cv2.imread('blurry_image.jpg') sharp_image = cv2.imread('sharp_image.jpg') # 数据预处理和归一化 blurry_image = cv2.cvtColor(blurry_image, cv2.COLOR_BGR2GRAY) sharp_image = cv2.cvtColor(sharp_image, cv2.COLOR_BGR2GRAY) blurry_image = np.expand_dims(blurry_image, axis=-1) sharp_image = np.expand_dims(sharp_image, axis=-1) blurry_image = blurry_image / 255. sharp_image = sharp_image / 255. # 定义生成器和判别器网络 def generator(): # 定义生成器网络结构,例如使用全卷积神经网络 ... def discriminator(): # 定义判别器网络结构,例如使用卷积神经网络 ... # 定义损失函数 def loss_function(real_image, fake_image): # 计算生成器损失和判别器损失 ... # 定义优化器 generator_optimizer = tf.keras.optimizers.Adam(learning_rate=0.001) discriminator_optimizer = tf.keras.optimizers.Adam(learning_rate=0.001) # 定义训练循环 @tf.function def train_step(blurry_image, sharp_image): # 定义训练循环,包括前向传播、反向传播和优化器更新 ... # 训练模型 for epoch in range(num_epochs): for i in range(num_batches): blurry_batch = ... sharp_batch = ... train_step(blurry_batch, sharp_batch) # 生成清晰图像 def generate_sharp_image(blurry_image): fake_sharp_image = generator(blurry_image, training=False) return fake_sharp_image # 测试模型 test_blurry_image = cv2.imread('test_blurry_image.jpg') test_blurry_image = cv2.cvtColor(test_blurry_image, cv2.COLOR_BGR2GRAY) test_blurry_image = np.expand_dims(test_blurry_image, axis=-1) test_blurry_image = test_blurry_image / 255. test_sharp_image = generate_sharp_image(test_blurry_image) test_sharp_image = test_sharp_image * 255. test_sharp_image = np.clip(test_sharp_image, 0, 255) test_sharp_image = test_sharp_image.astype(np.uint8) # 显示结果 cv2.imshow('Blurry Image', test_blurry_image) cv2.imshow('Sharp Image', test_sharp_image) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在这个示例中,我们首先加载了一些模糊图像和对应的清晰图像,并将它们进行了预处理和归一化。然后,我们定义了生成器和判别器网络,并使用对抗训练的方法来训练这些网络。最后,我们使用训练好的生成器网络来生成清晰图像,并将其与模糊图像一起显示出来。 需要注意的是,这个示例只是一个简单的对抗神经网络应用程序,实际情况下可能需要更复杂的算法和模型来实现更准确的图像去模糊效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值