diff --git a/.gitignore b/.gitignore index 9a477bff9..2a87551a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ notebooks +*.checkpoints diff --git a/tutorials/60-minute-blitz.jl b/Introduction to Flux/60-minute-blitz.jl similarity index 100% rename from tutorials/60-minute-blitz.jl rename to Introduction to Flux/60-minute-blitz.jl diff --git a/tutorials/Manifest.toml b/Introduction to Flux/Manifest.toml similarity index 100% rename from tutorials/Manifest.toml rename to Introduction to Flux/Manifest.toml diff --git a/tutorials/Project.toml b/Introduction to Flux/Project.toml similarity index 100% rename from tutorials/Project.toml rename to Introduction to Flux/Project.toml diff --git a/vision/mnist/Manifest.toml b/vision/Auto Encoder/Manifest.toml similarity index 100% rename from vision/mnist/Manifest.toml rename to vision/Auto Encoder/Manifest.toml diff --git a/vision/mnist/Project.toml b/vision/Auto Encoder/Project.toml similarity index 100% rename from vision/mnist/Project.toml rename to vision/Auto Encoder/Project.toml diff --git a/vision/Auto Encoder/README.md b/vision/Auto Encoder/README.md new file mode 100644 index 000000000..5c4e4881d --- /dev/null +++ b/vision/Auto Encoder/README.md @@ -0,0 +1,3 @@ +# Simple Auto Encoder + +- Encoder decoder architecture \ No newline at end of file diff --git a/vision/Auto Encoder/autoencoder.ipynb b/vision/Auto Encoder/autoencoder.ipynb new file mode 100644 index 000000000..01da4cc0c --- /dev/null +++ b/vision/Auto Encoder/autoencoder.ipynb @@ -0,0 +1,184 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "using Flux, Flux.Data.MNIST\n", + "using Flux: @epochs, onehotbatch, mse, throttle\n", + "using Base.Iterators\n", + "using CuArrays\n", + "using Images" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Encode MNIST images as compressed vectors that can later be decoded back into images.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "imgs = MNIST.images()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Partition into batches of size 1000" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = [float(hcat(vec.(imgs)...)) for imgs in partition(imgs, 1000)]\n", + "data = gpu.(data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "N = 32 # Size of the encoding" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- You can try to make the encoder/decoder network larger\n", + "- Also, the output of encoder is a coding of the given input.\n", + "- In this case, the input dimension is 28^2 and the output dimension of\n", + "- encoder is 32. This implies that the coding is a compressed representation.\n", + "- We can make lossy compression via this `encoder`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "encoder = Dense(28^2, N, leakyrelu) |> gpu\n", + "decoder = Dense(N, 28^2, leakyrelu) |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "m = Chain(encoder, decoder)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "loss(x) = mse(m(x), x)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "evalcb = throttle(() -> @show(loss(data[1])), 5)\n", + "opt = ADAM()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Train" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "@epochs 10 Flux.train!(loss, params(m), zip(data), opt, cb = evalcb)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Sample output" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "img(x::Vector) = Gray.(reshape(clamp.(x, 0, 1), 28, 28))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "function sample()\n", + " # 20 random digits\n", + " before = [imgs[i] for i in rand(1:length(imgs), 20)]\n", + " # Before and after images\n", + " after = img.(map(x -> cpu(m)(float(vec(x))).data, before))\n", + " # Stack them all together\n", + " hcat(vcat.(before, after)...)\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "save(\"sample.png\", sample())" + ] + } + ] +} \ No newline at end of file diff --git a/vision/Auto Encoder/autoencoder.jl b/vision/Auto Encoder/autoencoder.jl new file mode 100644 index 000000000..30b413184 --- /dev/null +++ b/vision/Auto Encoder/autoencoder.jl @@ -0,0 +1,81 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% +using Flux, Flux.Data.MNIST +using Flux: @epochs, onehotbatch, mse, throttle +using Base.Iterators +using CuArrays +using Images + +# %% [markdown] +# ## Encode MNIST images as compressed vectors that can later be decoded back into images. +# + +# %% + +imgs = MNIST.images() + +# %% [markdown] +# # Partition into batches of size 1000 + +# %% +data = [float(hcat(vec.(imgs)...)) for imgs in partition(imgs, 1000)] +data = gpu.(data) + + +# %% +N = 32 # Size of the encoding + +# %% [markdown] +# - You can try to make the encoder/decoder network larger +# - Also, the output of encoder is a coding of the given input. +# - In this case, the input dimension is 28^2 and the output dimension of +# - encoder is 32. This implies that the coding is a compressed representation. +# - We can make lossy compression via this `encoder`. + +# %% +encoder = Dense(28^2, N, leakyrelu) |> gpu +decoder = Dense(N, 28^2, leakyrelu) |> gpu + + +# %% +m = Chain(encoder, decoder) + + +# %% +loss(x) = mse(m(x), x) + + +# %% + +evalcb = throttle(() -> @show(loss(data[1])), 5) +opt = ADAM() + +# %% [markdown] +# ## Train + +# %% +@epochs 10 Flux.train!(loss, params(m), zip(data), opt, cb = evalcb) + +# %% [markdown] +# # Sample output + +# %% +img(x::Vector) = Gray.(reshape(clamp.(x, 0, 1), 28, 28)) + + +# %% +function sample() + # 20 random digits + before = [imgs[i] for i in rand(1:length(imgs), 20)] + # Before and after images + after = img.(map(x -> cpu(m)(float(vec(x))).data, before)) + # Stack them all together + hcat(vcat.(before, after)...) +end + + +# %% +save("sample.png", sample()) + + diff --git a/vision/cppn/Manifest.toml b/vision/Compositional Pattern Network/Manifest.toml similarity index 100% rename from vision/cppn/Manifest.toml rename to vision/Compositional Pattern Network/Manifest.toml diff --git a/vision/cppn/Project.toml b/vision/Compositional Pattern Network/Project.toml similarity index 100% rename from vision/cppn/Project.toml rename to vision/Compositional Pattern Network/Project.toml diff --git a/vision/Compositional Pattern Network/README.md b/vision/Compositional Pattern Network/README.md new file mode 100644 index 000000000..00b08a6ba --- /dev/null +++ b/vision/Compositional Pattern Network/README.md @@ -0,0 +1,5 @@ +# Generating Abstract Patterns with Compositional Pattern Producing Network + +- [Link to post](https://blog.otoro.net/2016/03/25/generating-abstract-patterns-with-tensorflow/) + + diff --git a/vision/Compositional Pattern Network/cppn.ipynb b/vision/Compositional Pattern Network/cppn.ipynb new file mode 100644 index 000000000..d3f14dbab --- /dev/null +++ b/vision/Compositional Pattern Network/cppn.ipynb @@ -0,0 +1,285 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "using Images\n", + "using Flux" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "262144" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "z_dim = 2\n", + "x_dim = 512\n", + "y_dim = 512\n", + "N = 14\n", + "hidden = 9\n", + "batch_size = 1024\n", + "n = x_dim * y_dim" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## cast 0:x-1 to -0.5:0.5" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "cast (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "\n", + "cast(x) = [range(-0.5, stop=0.5, step=1/(x - 1))...]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "262144-element Array{Float64,1}:\n 0.7071067811865476\n 0.7057243672141199\n 0.7043446771602189\n 0.702967727063262\n 0.7015935330555991\n 0.7002221113638016\n 0.6988534783089481\n 0.6974876503069023\n 0.6961246438685855\n 0.6947644756002421\n 0.6934071622036989\n 0.6920527204766176\n 0.6907011673127395\n ⋮\n 0.6920527204766176\n 0.6934071622036989\n 0.6947644756002421\n 0.6961246438685855\n 0.6974876503069023\n 0.6988534783089481\n 0.7002221113638016\n 0.7015935330555991\n 0.702967727063262\n 0.7043446771602189\n 0.7057243672141199\n 0.7071067811865476" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "xs, ys = cast(x_dim), cast(y_dim)\n", + "xs = repeat(xs, inner=(y_dim))\n", + "ys = repeat(ys, outer=(x_dim))\n", + "rs = sqrt.(xs.^2 + ys.^2)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "unit (generic function with 4 methods)" + }, + "metadata": {}, + "execution_count": 45 + } + ], + "source": [ + "unit(in=N, out=N, f=tanh) = Dense(in, out, f, initW=randn)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "11-element Array{Any,1}:\n Dense(5, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 1, σ)" + }, + "metadata": {}, + "execution_count": 46 + } + ], + "source": [ + "layers = Any[unit(3 + z_dim), [unit() for _ in 1:hidden]..., unit(N, 1, σ)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- In essence, CPPN is just a function, c = f(x, y), that defines the intensity of the image for every point in space." + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getColorAt (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 47 + } + ], + "source": [ + "model = Chain(layers...)\n", + "getColorAt(x) = Flux.data(model(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Make batches from the data" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "batch (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 48 + } + ], + "source": [ + "function batch(arr, s)\n", + " l = size(arr, 2)\n", + " batches = [arr[:, i:min(i+s-1, l)] for i=1:s:l]\n", + " batches\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create image with intensities" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getImage (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 49 + } + ], + "source": [ + "function getImage(z)\n", + " z = repeat(reshape(z, 1, z_dim), outer=(n, 1))\n", + " coords = hcat(xs, ys, rs, z)'\n", + " coords = batch(coords, batch_size)\n", + " pixels = [Gray.(hcat(getColorAt.(coords)...))...]\n", + " reshape(pixels, y_dim, x_dim)\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "saveImg (generic function with 2 methods)" + }, + "metadata": {}, + "execution_count": 50 + } + ], + "source": [ + "function saveImg(z, image_path=\"sample.png\")\n", + " imgg = getImage(z)\n", + " save(image_path, imgg)\n", + " imgg\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Will generate at random everytime" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10-element Array{Array{Gray{Float64},2},1}:\n [Gray{Float64}(0.5946810419058337) Gray{Float64}(0.5844071218782684) … Gray{Float64}(0.15290018571840844) Gray{Float64}(0.15713981219146686); Gray{Float64}(0.6045090537341339) Gray{Float64}(0.5949466340725956) … Gray{Float64}(0.14036278476817127) Gray{Float64}(0.1443107836337645); … ; Gray{Float64}(0.24997947367144818) Gray{Float64}(0.3941396770541056) … Gray{Float64}(0.9202468729908154) Gray{Float64}(0.9346036508108042); Gray{Float64}(0.322760625913554) Gray{Float64}(0.419712705310896) … Gray{Float64}(0.9263213744240756) Gray{Float64}(0.9397232772490718)]\n [Gray{Float64}(0.11819501133927904) Gray{Float64}(0.11675908787762) … Gray{Float64}(0.7648690894451594) Gray{Float64}(0.7641494669450892); Gray{Float64}(0.11122510245225029) Gray{Float64}(0.10999837637012912) … Gray{Float64}(0.7760557634698783) Gray{Float64}(0.7774299862906915); … ; Gray{Float64}(0.9884111268623222) Gray{Float64}(0.9878463147302998) … Gray{Float64}(0.040437062420612985) Gray{Float64}(0.040251734266504434); Gray{Float64}(0.9884330525895296) Gray{Float64}(0.987905539429019) … Gray{Float64}(0.040855481496096094) Gray{Float64}(0.040774286483127704)]\n [Gray{Float64}(0.30111332470639385) Gray{Float64}(0.36931233674515107) … Gray{Float64}(0.9802169034653367) Gray{Float64}(0.980004397204283); Gray{Float64}(0.30198454950502784) Gray{Float64}(0.3265565045763157) … Gray{Float64}(0.9783248361872814) Gray{Float64}(0.9780989557593958); … ; Gray{Float64}(0.9870886870343462) Gray{Float64}(0.9867567536711443) … Gray{Float64}(0.13938127358070224) Gray{Float64}(0.1397740669694261); Gray{Float64}(0.9876162740565131) Gray{Float64}(0.9870729933165118) … Gray{Float64}(0.1394965721555591) Gray{Float64}(0.13991613416421314)]\n [Gray{Float64}(0.9973447963359813) Gray{Float64}(0.997383623223014) … Gray{Float64}(0.808199414391733) Gray{Float64}(0.8062856555648144); Gray{Float64}(0.9972773247520194) Gray{Float64}(0.9973201256078482) … Gray{Float64}(0.8173400212101277) Gray{Float64}(0.8154669108408432); … ; Gray{Float64}(0.14277984746933867) Gray{Float64}(0.1401673145569529) … Gray{Float64}(0.9820610565946315) Gray{Float64}(0.9861721958463162); Gray{Float64}(0.137213528249731) Gray{Float64}(0.14784284205637116) … Gray{Float64}(0.9782245631284652) Gray{Float64}(0.9836852366385818)]\n [Gray{Float64}(0.5280506047038377) Gray{Float64}(0.5296275960193153) … Gray{Float64}(0.21844161164706746) Gray{Float64}(0.21792058018356017); Gray{Float64}(0.5289058601233677) Gray{Float64}(0.530437210925873) … Gray{Float64}(0.21677907275196628) Gray{Float64}(0.2162595974529549); … ; Gray{Float64}(0.5322501889696164) Gray{Float64}(0.4973627768129481) … Gray{Float64}(0.15019248803392207) Gray{Float64}(0.12322683166948917); Gray{Float64}(0.5035340359632582) Gray{Float64}(0.4611392659481996) … Gray{Float64}(0.17010823449705706) Gray{Float64}(0.15265725701766789)]\n [Gray{Float64}(0.9978572825779828) Gray{Float64}(0.997784162879517) … Gray{Float64}(0.7923563110546755) Gray{Float64}(0.7298367585811415); Gray{Float64}(0.9977580158444547) Gray{Float64}(0.9976035272703733) … Gray{Float64}(0.19749284720224836) Gray{Float64}(0.15161258667570607); … ; Gray{Float64}(0.5844857482501201) Gray{Float64}(0.5702894093419769) … Gray{Float64}(0.06736554935132213) Gray{Float64}(0.07106875259503888); Gray{Float64}(0.5837236207932673) Gray{Float64}(0.5684540709659316) … Gray{Float64}(0.0720502989878908) Gray{Float64}(0.07644867913737839)]\n [Gray{Float64}(0.6237526395887424) Gray{Float64}(0.6269262963671303) … Gray{Float64}(0.1311215870642958) Gray{Float64}(0.13080990703261483); Gray{Float64}(0.6249924675099126) Gray{Float64}(0.628182141095554) … Gray{Float64}(0.12917766592287983) Gray{Float64}(0.1288833608702311); … ; Gray{Float64}(0.5084924250807725) Gray{Float64}(0.5082864547802465) … Gray{Float64}(0.3460909858668719) Gray{Float64}(0.3576344073773565); Gray{Float64}(0.5075344857806848) Gray{Float64}(0.5073312351345307) … Gray{Float64}(0.33777870691268463) Gray{Float64}(0.3482836434388344)]\n [Gray{Float64}(0.15008242040718592) Gray{Float64}(0.1561357486320554) … Gray{Float64}(0.03335540918013374) Gray{Float64}(0.03304361810872566); Gray{Float64}(0.15143073863591036) Gray{Float64}(0.15749410714776818) … Gray{Float64}(0.03451512808311513) Gray{Float64}(0.03415860613846207); … ; Gray{Float64}(0.028314124734372618) Gray{Float64}(0.028239552033001606) … Gray{Float64}(0.21148328958296184) Gray{Float64}(0.2085265164746206); Gray{Float64}(0.028281831284618444) Gray{Float64}(0.02821503723013225) … Gray{Float64}(0.21281683756288636) Gray{Float64}(0.20985201055606217)]\n [Gray{Float64}(0.539654439429861) Gray{Float64}(0.5586826490751261) … Gray{Float64}(0.33642858386966107) Gray{Float64}(0.32643899480548); Gray{Float64}(0.5426006347040554) Gray{Float64}(0.5612857381321137) … Gray{Float64}(0.3292006707085808) Gray{Float64}(0.318313229943188); … ; Gray{Float64}(0.5707348756442485) Gray{Float64}(0.6225053536183021) … Gray{Float64}(0.18327159657513448) Gray{Float64}(0.1994099221586931); Gray{Float64}(0.6085782839747482) Gray{Float64}(0.6598773551387486) … Gray{Float64}(0.16924592246131395) Gray{Float64}(0.18735413296904374)]\n [Gray{Float64}(0.27517661584805075) Gray{Float64}(0.2780619461164357) … Gray{Float64}(0.04551957533645665) Gray{Float64}(0.04482568087452583); Gray{Float64}(0.2767982452416591) Gray{Float64}(0.2796918739811609) … Gray{Float64}(0.04651389969453936) Gray{Float64}(0.045841702214116466); … ; Gray{Float64}(0.9464773358640313) Gray{Float64}(0.9458535612675792) … Gray{Float64}(0.3541721646132875) Gray{Float64}(0.34256547573330265); Gray{Float64}(0.9458198498460076) Gray{Float64}(0.9458341907119691) … Gray{Float64}(0.354674401855659) Gray{Float64}(0.3437442242037584)]", + "text/html": "
(a vector displayed as a row to save space)
" + }, + "metadata": {}, + "execution_count": 51 + } + ], + "source": [ + "[saveImg(rand(z_dim)) for _ in 1:10]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/cppn/cppn.jl b/vision/Compositional Pattern Network/cppn.jl similarity index 60% rename from vision/cppn/cppn.jl rename to vision/Compositional Pattern Network/cppn.jl index 0e2e7f237..68528a150 100644 --- a/vision/cppn/cppn.jl +++ b/vision/Compositional Pattern Network/cppn.jl @@ -1,9 +1,11 @@ -# Ref: http://blog.otoro.net/2016/03/25/generating-abstract-patterns-with-tensorflow/ - +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% using Images using Flux -# set parameters + +# %% z_dim = 2 x_dim = 512 y_dim = 512 @@ -12,36 +14,47 @@ hidden = 9 batch_size = 1024 n = x_dim * y_dim + +# %% # cast 0:x-1 to -0.5:0.5 cast(x) = [range(-0.5, stop=0.5, step=1/(x - 1))...] + +# %% xs, ys = cast(x_dim), cast(y_dim) xs = repeat(xs, inner=(y_dim)) ys = repeat(ys, outer=(x_dim)) rs = sqrt.(xs.^2 + ys.^2) -# sample weigths from a gaussian distribution + +# %% unit(in=N, out=N, f=tanh) = Dense(in, out, f, initW=randn) -# input -> [x, y, r, z...] -layers = Any[unit(3 + z_dim)] -for i=1:hidden - push!(layers, unit()) -end -push!(layers, unit(N, 1, σ)) +# %% +layers = Any[unit(3 + z_dim), [unit() for _ in 1:hidden]..., unit(N, 1, σ)] + +# %% [markdown] +# - In essence, CPPN is just a function, c = f(x, y), that defines the intensity of the image for every point in space. + +# %% model = Chain(layers...) getColorAt(x) = Flux.data(model(x)) +# %% [markdown] +# ## Make batches from the data + +# %% function batch(arr, s) - batches = [] l = size(arr, 2) - for i=1:s:l - push!(batches, arr[:, i:min(i+s-1, l)]) - end + batches = [arr[:, i:min(i+s-1, l)] for i=1:s:l] batches end +# %% [markdown] +# ## Create image with intensities + +# %% function getImage(z) z = repeat(reshape(z, 1, z_dim), outer=(n, 1)) coords = hcat(xs, ys, rs, z)' @@ -50,10 +63,22 @@ function getImage(z) reshape(pixels, y_dim, x_dim) end + +# %% function saveImg(z, image_path="sample.png") imgg = getImage(z) save(image_path, imgg) imgg end +# %% [markdown] +# ## Will generate at random everytime + +# %% saveImg(rand(z_dim)) + + +# %% + + + diff --git a/vision/Multi Layer Perceptron/Manifest.toml b/vision/Multi Layer Perceptron/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/Multi Layer Perceptron/Manifest.toml @@ -0,0 +1,582 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/Multi Layer Perceptron/Project.toml b/vision/Multi Layer Perceptron/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/Multi Layer Perceptron/Project.toml @@ -0,0 +1,8 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/Multi Layer Perceptron/README.md b/vision/Multi Layer Perceptron/README.md new file mode 100644 index 000000000..4ea3069f7 --- /dev/null +++ b/vision/Multi Layer Perceptron/README.md @@ -0,0 +1,3 @@ +# A simple MLP + +- A good place to start with Deep Learning using Flux \ No newline at end of file diff --git a/vision/Multi Layer Perceptron/mlp.ipynb b/vision/Multi Layer Perceptron/mlp.ipynb new file mode 100644 index 000000000..1772c9f66 --- /dev/null +++ b/vision/Multi Layer Perceptron/mlp.ipynb @@ -0,0 +1,275 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "using Flux, Flux.Data.MNIST, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated\n", + "using CuArrays" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Classify MNIST digits with a simple multi-layer-perceptron\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "60000-element Array{Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},1}:\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n ⋮\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]" + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "imgs = MNIST.images()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Stack images into one large batch" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "60000-element Array{Int64,1}:\n 5\n 0\n 4\n 1\n 9\n 2\n 1\n 3\n 1\n 4\n 3\n 5\n 3\n ⋮\n 7\n 8\n 9\n 2\n 9\n 5\n 1\n 8\n 3\n 5\n 6\n 8" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "\n", + "X = hcat(float.(reshape.(imgs, :))...) |> gpu\n", + "\n", + "labels = MNIST.labels()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# One-hot-encode the labels" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10×60000 Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}:\n 0 1 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0\n 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0\n 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 1 0 0 0 0 0 0 0 0 0 0 1 0 … 0 0 0 0 0 1 0 0 0 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1\n 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0" + }, + "metadata": {}, + "execution_count": 5 + }, + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`\n└ @ GPUArrays /home/subhaditya/.julia/packages/GPUArrays/JqOUg/src/host/indexing.jl:43\n" + } + ], + "source": [ + "\n", + "Y = onehotbatch(labels, 0:9) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain(Dense(784, 32, relu), Dense(32, 10), softmax)" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "\n", + "m = Chain(\n", + " Dense(28^2, 32, relu),\n", + " Dense(32, 10),\n", + " softmax) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "loss (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "\n", + "loss(x, y) = crossentropy(m(x), y)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "accuracy (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "\n", + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "\n", + "dataset = repeated((X, Y), 200)\n", + "evalcb = () -> @show(loss(X, Y))\n", + "opt = ADAM()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Train" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "loss(X, Y) = 2.2866402f0\n" + } + ], + "source": [ + "\n", + "Flux.train!(loss, params(m), dataset, opt, cb = throttle(evalcb, 10))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "accuracy(X, Y)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Test set accuracy\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tX = hcat(float.(reshape.(MNIST.images(:test), :))...) |> gpu\n", + "tY = onehotbatch(MNIST.labels(:test), 0:9) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "accuracy(tX, tY)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/mnist/mlp.jl b/vision/Multi Layer Perceptron/mlp.jl similarity index 61% rename from vision/mnist/mlp.jl rename to vision/Multi Layer Perceptron/mlp.jl index 06aeaad75..edd843690 100644 --- a/vision/mnist/mlp.jl +++ b/vision/Multi Layer Perceptron/mlp.jl @@ -1,37 +1,88 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% using Flux, Flux.Data.MNIST, Statistics using Flux: onehotbatch, onecold, crossentropy, throttle using Base.Iterators: repeated -# using CuArrays +using CuArrays -# Classify MNIST digits with a simple multi-layer-perceptron +# %% [markdown] +# # Classify MNIST digits with a simple multi-layer-perceptron +# +# %% imgs = MNIST.images() -# Stack images into one large batch + +# %% [markdown] +# +# # Stack images into one large batch + +# %% + X = hcat(float.(reshape.(imgs, :))...) |> gpu labels = MNIST.labels() -# One-hot-encode the labels + +# %% [markdown] +# # One-hot-encode the labels + +# %% + Y = onehotbatch(labels, 0:9) |> gpu + +# %% + m = Chain( Dense(28^2, 32, relu), Dense(32, 10), softmax) |> gpu + +# %% + loss(x, y) = crossentropy(m(x), y) + +# %% + accuracy(x, y) = mean(onecold(m(x)) .== onecold(y)) + +# %% + dataset = repeated((X, Y), 200) evalcb = () -> @show(loss(X, Y)) opt = ADAM() +# %% [markdown] +# # Train + +# %% + Flux.train!(loss, params(m), dataset, opt, cb = throttle(evalcb, 10)) + +# %% + accuracy(X, Y) -# Test set accuracy +# %% [markdown] +# +# # Test set accuracy +# + +# %% tX = hcat(float.(reshape.(MNIST.images(:test), :))...) |> gpu tY = onehotbatch(MNIST.labels(:test), 0:9) |> gpu + +# %% + accuracy(tX, tY) + + +# %% + + + diff --git a/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb b/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb new file mode 100644 index 000000000..293b9daca --- /dev/null +++ b/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb @@ -0,0 +1,552 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T22:10:02.179000+04:00", + "start_time": "2020-08-11T18:09:21.430Z" + }, + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "┌ Info: Precompiling Flux [587475ba-b771-5e3f-ad9e-33799f191a9c]\n", + "└ @ Base loading.jl:1278\n", + "┌ Warning: Package Flux does not have Zygote in its dependencies:\n", + "│ - If you have Flux checked out for development and have\n", + "│ added Zygote as a dependency but haven't updated your primary\n", + "│ environment's manifest file, try `Pkg.resolve()`.\n", + "│ - Otherwise you may need to report an issue with Flux\n", + "└ Loading Zygote into Flux from project dependency, future warnings for Flux are suppressed.\n", + "┌ Warning: Package MacroTools does not have Markdown in its dependencies:\n", + "│ - If you have MacroTools checked out for development and have\n", + "│ added Markdown as a dependency but haven't updated your primary\n", + "│ environment's manifest file, try `Pkg.resolve()`.\n", + "│ - Otherwise you may need to report an issue with MacroTools\n", + "└ Loading Markdown into MacroTools from project dependency, future warnings for MacroTools are suppressed.\n", + "┌ Warning: The call to compilecache failed to create a usable precompiled cache file for ZygoteRules [700de1a5-db45-46bc-99cf-38207098b444]\n", + "│ exception = Required dependency MacroTools [1914dd2f-81c6-5fcd-8719-6d5c9610ff09] failed to load from a cache file.\n", + "└ @ Base loading.jl:1042\n", + "┌ Warning: Package MacroTools does not have Markdown in its dependencies:\n", + "│ - If you have MacroTools checked out for development and have\n", + "│ added Markdown as a dependency but haven't updated your primary\n", + "│ environment's manifest file, try `Pkg.resolve()`.\n", + "│ - Otherwise you may need to report an issue with MacroTools\n", + "└ Loading Markdown into MacroTools from project dependency, future warnings for MacroTools are suppressed.\n", + "┌ Warning: Package Requires does not have UUIDs in its dependencies:\n", + "│ - If you have Requires checked out for development and have\n", + "│ added UUIDs as a dependency but haven't updated your primary\n", + "│ environment's manifest file, try `Pkg.resolve()`.\n", + "│ - Otherwise you may need to report an issue with Requires\n", + "└ Loading UUIDs into Requires from project dependency, future warnings for Requires are suppressed.\n", + "┌ Warning: The call to compilecache failed to create a usable precompiled cache file for ChainRules [082447d4-558c-5d27-93f4-14fc19e9eca2]\n", + "│ exception = Required dependency Requires [ae029012-a4dd-5104-9daa-d747884805df] failed to load from a cache file.\n", + "└ @ Base loading.jl:1042\n", + "┌ Warning: Package Requires does not have UUIDs in its dependencies:\n", + "│ - If you have Requires checked out for development and have\n", + "│ added UUIDs as a dependency but haven't updated your primary\n", + "│ environment's manifest file, try `Pkg.resolve()`.\n", + "│ - Otherwise you may need to report an issue with Requires\n", + "└ Loading UUIDs into Requires from project dependency, future warnings for Requires are suppressed.\n", + "ERROR: LoadError: ArgumentError: Package SpecialFunctions does not have OpenSpecFun_jll in its dependencies:\n", + "- If you have SpecialFunctions checked out for development and have\n", + " added OpenSpecFun_jll as a dependency but haven't updated your primary\n", + " environment's manifest file, try `Pkg.resolve()`.\n", + "- Otherwise you may need to report an issue with SpecialFunctions\n", + "Stacktrace:\n", + " [1] require(::Module, ::Symbol) at ./loading.jl:906\n", + " [2] include(::Function, ::Module, ::String) at ./Base.jl:380\n", + " [3] include(::Module, ::String) at ./Base.jl:368\n", + " [4] top-level scope at none:2\n", + " [5] eval at ./boot.jl:331 [inlined]\n", + " [6] eval(::Expr) at ./client.jl:467\n", + " [7] top-level scope at ./none:3\n", + "in expression starting at /home/subhaditya/.julia/packages/SpecialFunctions/LC8dm/src/SpecialFunctions.jl:3\n", + "ERROR: LoadError: LoadError: LoadError: Failed to precompile SpecialFunctions [276daf66-3868-5448-9aa4-cd146d93841b] to /home/subhaditya/.julia/compiled/v1.5/SpecialFunctions/78gOt_L66GW.ji.\n", + "Stacktrace:\n", + " [1] error(::String) at ./error.jl:33\n", + " [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1290\n", + " [3] _require(::Base.PkgId) at ./loading.jl:1030\n", + " [4] require(::Base.PkgId) at ./loading.jl:928\n", + " [5] require(::Module, ::Symbol) at ./loading.jl:923\n", + " [6] include(::Function, ::Module, ::String) at ./Base.jl:380\n", + " [7] include at ./Base.jl:368 [inlined]\n", + " [8] include(::String) at /home/subhaditya/.julia/packages/Zygote/seGHk/src/forward/Forward.jl:1\n", + " [9] top-level scope at /home/subhaditya/.julia/packages/Zygote/seGHk/src/forward/Forward.jl:11\n", + " [10] include(::Function, ::Module, ::String) at ./Base.jl:380\n", + " [11] include at ./Base.jl:368 [inlined]\n", + " [12] include(::String) at /home/subhaditya/.julia/packages/Zygote/seGHk/src/Zygote.jl:1\n", + " [13] top-level scope at /home/subhaditya/.julia/packages/Zygote/seGHk/src/Zygote.jl:22\n", + " [14] include(::Function, ::Module, ::String) at ./Base.jl:380\n", + " [15] include(::Module, ::String) at ./Base.jl:368\n", + " [16] top-level scope at none:2\n", + " [17] eval at ./boot.jl:331 [inlined]\n", + " [18] eval(::Expr) at ./client.jl:467\n", + " [19] top-level scope at ./none:3\n", + "in expression starting at /home/subhaditya/.julia/packages/Zygote/seGHk/src/forward/number.jl:1\n", + "in expression starting at /home/subhaditya/.julia/packages/Zygote/seGHk/src/forward/Forward.jl:11\n", + "in expression starting at /home/subhaditya/.julia/packages/Zygote/seGHk/src/Zygote.jl:22\n", + "ERROR: LoadError: Failed to precompile Zygote [e88e6eb3-aa80-5325-afca-941959d7151f] to /home/subhaditya/.julia/compiled/v1.5/Zygote/4kbLI_L66GW.ji.\n", + "Stacktrace:\n", + " [1] error(::String) at ./error.jl:33\n", + " [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1290\n", + " [3] _require(::Base.PkgId) at ./loading.jl:1030\n", + " [4] require(::Base.PkgId) at ./loading.jl:928\n", + " [5] require(::Module, ::Symbol) at ./loading.jl:923\n", + " [6] include(::Function, ::Module, ::String) at ./Base.jl:380\n", + " [7] include(::Module, ::String) at ./Base.jl:368\n", + " [8] top-level scope at none:2\n", + " [9] eval at ./boot.jl:331 [inlined]\n", + " [10] eval(::Expr) at ./client.jl:467\n", + " [11] top-level scope at ./none:3\n", + "in expression starting at /home/subhaditya/.julia/packages/Flux/05b38/src/Flux.jl:7\n" + ] + }, + { + "ename": "LoadError", + "evalue": "Failed to precompile Flux [587475ba-b771-5e3f-ad9e-33799f191a9c] to /home/subhaditya/.julia/compiled/v1.5/Flux/QdkVy_L66GW.ji.", + "output_type": "error", + "traceback": [ + "Failed to precompile Flux [587475ba-b771-5e3f-ad9e-33799f191a9c] to /home/subhaditya/.julia/compiled/v1.5/Flux/QdkVy_L66GW.ji.", + "", + "Stacktrace:", + " [1] error(::String) at ./error.jl:33", + " [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1290", + " [3] _require(::Base.PkgId) at ./loading.jl:1030", + " [4] require(::Base.PkgId) at ./loading.jl:928", + " [5] require(::Module, ::Symbol) at ./loading.jl:923", + " [6] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091" + ] + } + ], + "source": [ + "using Flux, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated, partition\n", + "using Metalhead:trainimgs, CIFAR10\n", + "using Images" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T21:52:29.839000+04:00", + "start_time": "2020-08-11T17:52:25.688Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "getarray (generic function with 1 method)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T21:47:47.459000+04:00", + "start_time": "2020-08-11T17:47:47.448Z" + }, + "scrolled": true + }, + "outputs": [ + { + "ename": "LoadError", + "evalue": "UndefVarError: trainimgs not defined", + "output_type": "error", + "traceback": [ + "UndefVarError: trainimgs not defined", + "", + "Stacktrace:", + " [1] top-level scope at In[7]:1", + " [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091" + ] + } + ], + "source": [ + "X = trainimgs(CIFAR10)\n", + "imgs = [getarray(X[i].img) for i in 1:50000];\n", + "labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10);\n", + "train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]);" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:29:25.375000+04:00", + "start_time": "2020-08-11T12:28:59.367Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "10×1000 Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}:\n", + " 0 0 0 0 1 0 1 0 0 0 0 0 0 … 0 0 0 0 1 0 1 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1\n", + " 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 1 0 0 0 0 0 0 0 … 1 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "valset = collect(49001:50000)\n", + "valX = cat(imgs[valset]..., dims = 4) |> gpu\n", + "valY = labels[:, valset] |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + " chain(A::Tuple...) = Chain(mapreduce(collect, vcat, A)...)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "conv_block(in_channels, out_channels) = (\n", + " Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), \n", + " BatchNorm(out_channels))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "double_conv(in_channels, out_channels) = (\n", + " conv_block(in_channels, out_channels),\n", + " conv_block(out_channels, out_channels),\n", + " MaxPool((2,2)))" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:05.168000+04:00", + "start_time": "2020-08-11T13:05:05.159Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "vgg16 (generic function with 2 methods)" + ] + }, + "execution_count": 173, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vgg16(initial_channels, num_classes) = chain(\n", + " double_conv(initial_channels, 64),\n", + " double_conv(64,128),\n", + " conv_block(128, 256),\n", + " double_conv(256, 256), \n", + " conv_block(256, 512),\n", + " double_conv(512, 512),\n", + " conv_block(512, 512),\n", + " double_conv(512, 512),\n", + " x -> reshape(x, :, size(x, 4)),\n", + " Dense(512, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, num_classes), \n", + " softmax\n", + " ) |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:08.454000+04:00", + "start_time": "2020-08-11T13:05:08.040Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Chain(Conv((3, 3), 3=>64, relu), BatchNorm(64), Conv((3, 3), 64=>64, relu), BatchNorm(64), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 64=>128, relu), BatchNorm(128), Conv((3, 3), 128=>128, relu), BatchNorm(128), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 128=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 256=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), #36, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" + ] + }, + "execution_count": 174, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m = vgg16()" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:11.842000+04:00", + "start_time": "2020-08-11T13:05:11.839Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "loss (generic function with 1 method)" + ] + }, + "execution_count": 178, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "loss(x, y) = crossentropy(m(x), y)" + ] + }, + { + "cell_type": "code", + "execution_count": 180, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:12.481000+04:00", + "start_time": "2020-08-11T13:05:12.447Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "accuracy (generic function with 1 method)" + ] + }, + "execution_count": 180, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))" + ] + }, + { + "cell_type": "code", + "execution_count": 181, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:13.807000+04:00", + "start_time": "2020-08-11T13:05:13.721Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#39#40\",Int64}}) (generic function with 1 method)" + ] + }, + "execution_count": 181, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "evalcb = throttle(() -> @show(accuracy(valX, valY)), 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 182, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:14.409000+04:00", + "start_time": "2020-08-11T13:05:14.407Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + ] + }, + "execution_count": 182, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "opt = ADAM()" + ] + }, + { + "cell_type": "code", + "execution_count": 183, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:07:16.455000+04:00", + "start_time": "2020-08-11T13:05:14.799Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "accuracy(valX, valY) = 0.112\n", + "accuracy(valX, valY) = 0.087\n", + "accuracy(valX, valY) = 0.087\n" + ] + }, + { + "ename": "LoadError", + "evalue": "TaskFailedException:\nInterruptException:\nStacktrace:\n [1] ntuple(::NNlib.var\"#4#5\"{Tuple{Int64,Int64,Int64},Tuple{Int64,Int64,Int64},Tuple{Int64,Int64,Int64},NTuple{6,Int64},Tuple{Int64,Int64,Int64}}, ::Int64) at ./ntuple.jl:17\n [2] output_size at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/dim_helpers/ConvDims.jl:120 [inlined]\n [3] im2col!(::SubArray{Float32,2,Array{Float32,3},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true}, ::SubArray{Float32,4,Array{Float32,5},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true}, ::DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:190\n [4] macro expansion at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:53 [inlined]\n [5] (::NNlib.var\"#349#threadsfor_fun#160\"{Array{Float32,3},Float32,Float32,Array{Float32,5},Array{Float32,5},Array{Float32,5},DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false},Int64,Int64,Int64,UnitRange{Int64}})(::Bool) at ./threadingconstructs.jl:81\n [6] (::NNlib.var\"#349#threadsfor_fun#160\"{Array{Float32,3},Float32,Float32,Array{Float32,5},Array{Float32,5},Array{Float32,5},DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false},Int64,Int64,Int64,UnitRange{Int64}})() at ./threadingconstructs.jl:48", + "output_type": "error", + "traceback": [ + "TaskFailedException:\nInterruptException:\nStacktrace:\n [1] ntuple(::NNlib.var\"#4#5\"{Tuple{Int64,Int64,Int64},Tuple{Int64,Int64,Int64},Tuple{Int64,Int64,Int64},NTuple{6,Int64},Tuple{Int64,Int64,Int64}}, ::Int64) at ./ntuple.jl:17\n [2] output_size at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/dim_helpers/ConvDims.jl:120 [inlined]\n [3] im2col!(::SubArray{Float32,2,Array{Float32,3},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true}, ::SubArray{Float32,4,Array{Float32,5},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true}, ::DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:190\n [4] macro expansion at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:53 [inlined]\n [5] (::NNlib.var\"#349#threadsfor_fun#160\"{Array{Float32,3},Float32,Float32,Array{Float32,5},Array{Float32,5},Array{Float32,5},DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false},Int64,Int64,Int64,UnitRange{Int64}})(::Bool) at ./threadingconstructs.jl:81\n [6] (::NNlib.var\"#349#threadsfor_fun#160\"{Array{Float32,3},Float32,Float32,Array{Float32,5},Array{Float32,5},Array{Float32,5},DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false},Int64,Int64,Int64,UnitRange{Int64}})() at ./threadingconstructs.jl:48", + "", + "Stacktrace:", + " [1] wait at ./task.jl:267 [inlined]", + " [2] threading_run(::Function) at ./threadingconstructs.jl:34", + " [3] macro expansion at ./threadingconstructs.jl:93 [inlined]", + " [4] conv_im2col!(::Array{Float32,5}, ::Array{Float32,5}, ::Array{Float32,5}, ::DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false}; col::Array{Float32,3}, alpha::Float32, beta::Float32) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:49", + " [5] conv_im2col! at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/impl/conv_im2col.jl:30 [inlined]", + " [6] #conv!#41 at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:53 [inlined]", + " [7] conv!(::Array{Float32,5}, ::Array{Float32,5}, ::Array{Float32,5}, ::DenseConvDims{3,(3, 3, 1),256,256,(1, 1, 1),(1, 1, 1, 1, 0, 0),(1, 1, 1),false}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:53", + " [8] conv!(::Array{Float32,4}, ::Array{Float32,4}, ::Array{Float32,4}, ::DenseConvDims{2,(3, 3),256,256,(1, 1),(1, 1, 1, 1),(1, 1),false}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:70", + " [9] conv! at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:70 [inlined]", + " [10] conv(::Array{Float32,4}, ::Array{Float32,4}, ::DenseConvDims{2,(3, 3),256,256,(1, 1),(1, 1, 1, 1),(1, 1),false}; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:116", + " [11] conv(::Array{Float32,4}, ::Array{Float32,4}, ::DenseConvDims{2,(3, 3),256,256,(1, 1),(1, 1, 1, 1),(1, 1),false}) at /home/subhaditya/.julia/packages/NNlib/FAI3o/src/conv.jl:114", + " [12] (::Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}})(::Array{Float32,4}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/conv.jl:61", + " [13] applychain(::Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},var\"#36#37\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 (repeats 13 times)", + " [14] (::Chain{Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},var\"#36#37\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}})(::Array{Float32,4}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:38", + " [15] accuracy(::Array{Float32,4}, ::Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}) at ./In[180]:1", + " [16] macro expansion at ./show.jl:641 [inlined]", + " [17] (::var\"#39#40\")() at ./In[181]:1", + " [18] throttled at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/utils.jl:302 [inlined]", + " [19] throttled at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/utils.jl:298 [inlined]", + " [20] macro expansion at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:93 [inlined]", + " [21] macro expansion at /home/subhaditya/.julia/packages/Juno/hEPx8/src/progress.jl:134 [inlined]", + " [22] train!(::typeof(loss), ::Zygote.Params, ::Array{Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}},1}, ::ADAM; cb::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#39#40\",Int64}}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:81", + " [23] top-level scope at In[183]:1", + " [24] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091" + ] + } + ], + "source": [ + "Flux.train!(loss, params(m), train, opt, cb = evalcb)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.5.0", + "language": "julia", + "name": "julia-1.5" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.5.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb b/vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb new file mode 100644 index 000000000..aac84acee --- /dev/null +++ b/vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb @@ -0,0 +1,429 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.051Z" + } + }, + "outputs": [], + "source": [ + "using Flux, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated, partition\n", + "using Metalhead:trainimgs, CIFAR10\n", + "using Images" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.691Z" + } + }, + "outputs": [], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.874Z" + } + }, + "outputs": [], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:24.076Z" + }, + "scrolled": true + }, + "outputs": [], + "source": [ + "X = trainimgs(CIFAR10)\n", + "imgs = [getarray(X[i].img) for i in 1:50000];\n", + "labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10);\n", + "train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:24.610Z" + } + }, + "outputs": [], + "source": [ + "valset = collect(49001:50000)\n", + "valX = cat(imgs[valset]..., dims = 4) |> gpu\n", + "valY = labels[:, valset] |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:24.858Z" + } + }, + "outputs": [], + "source": [ + " chain(A::Tuple...) = Chain(mapreduce(collect, vcat, A)...)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:25.027Z" + } + }, + "outputs": [], + "source": [ + "conv_block(in_channels, out_channels) = (\n", + " Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), \n", + " BatchNorm(out_channels))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "double_conv(in_channels, out_channels) = (\n", + " conv_block(in_channels, out_channels),\n", + " conv_block(out_channels, out_channels),\n", + " MaxPool((2,2)))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:25.499Z" + } + }, + "outputs": [], + "source": [ + "vgg19() = Chain(\n", + " Conv((3, 3), 3 => 64, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(64),\n", + " Conv((3, 3), 64 => 64, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(64),\n", + " MaxPool((2,2)),\n", + " Conv((3, 3), 64 => 128, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(128),\n", + " Conv((3, 3), 128 => 128, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(128),\n", + " MaxPool((2,2)),\n", + " Conv((3, 3), 128 => 256, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(256),\n", + " Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(256),\n", + " Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(256),\n", + " Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)),\n", + " MaxPool((2,2)),\n", + " Conv((3, 3), 256 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " MaxPool((2,2)),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " BatchNorm(512),\n", + " Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)),\n", + " MaxPool((2,2)),\n", + " x -> reshape(x, :, size(x, 4)),\n", + " Dense(512, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, 10),\n", + " softmax) |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:46.553000+04:00", + "start_time": "2020-08-11T13:14:45.389Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Chain(Conv((3, 3), 3=>64, relu), BatchNorm(64), Conv((3, 3), 64=>64, relu), BatchNorm(64), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 64=>128, relu), BatchNorm(128), Conv((3, 3), 128=>128, relu), BatchNorm(128), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 128=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 256=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), #7, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m = vgg19()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.788000+04:00", + "start_time": "2020-08-11T13:14:47.786Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "loss (generic function with 1 method)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "loss(x, y) = crossentropy(m(x), y)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.867000+04:00", + "start_time": "2020-08-11T13:14:47.866Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "accuracy (generic function with 1 method)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.990000+04:00", + "start_time": "2020-08-11T13:14:47.906Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#11#12\",Int64}}) (generic function with 1 method)" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "evalcb = throttle(() -> @show(accuracy(valX, valY)), 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:48.860000+04:00", + "start_time": "2020-08-11T13:13:19.436Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "opt = ADAM()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:16:10.370000+04:00", + "start_time": "2020-08-11T13:14:58.340Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "accuracy(valX, valY) = 0.119\n" + ] + }, + { + "ename": "LoadError", + "evalue": "InterruptException:", + "output_type": "error", + "traceback": [ + "InterruptException:", + "", + "Stacktrace:", + " [1] BatchNorm at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/normalise.jl:199 [inlined]", + " [2] _pullback(::Zygote.Context, ::BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [3] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [4] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [5] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [6] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [7] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [8] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [9] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [10] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [11] Chain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:38 [inlined]", + " [12] _pullback(::Zygote.Context, ::Chain{Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [13] loss at ./In[17]:1 [inlined]", + " [14] _pullback(::Zygote.Context, ::typeof(loss), ::Array{Float32,4}, ::Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [15] adjoint at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:179 [inlined]", + " [16] _pullback at /home/subhaditya/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]", + " [17] #17 at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:89 [inlined]", + " [18] _pullback(::Zygote.Context, ::Flux.Optimise.var\"#17#25\"{typeof(loss),Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}}}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [19] pullback(::Function, ::Zygote.Params) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:172", + " [20] gradient(::Function, ::Zygote.Params) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:53", + " [21] macro expansion at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:88 [inlined]", + " [22] macro expansion at /home/subhaditya/.julia/packages/Juno/hEPx8/src/progress.jl:134 [inlined]", + " [23] train!(::typeof(loss), ::Zygote.Params, ::Array{Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}},1}, ::ADAM; cb::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#11#12\",Int64}}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:81", + " [24] top-level scope at In[21]:1", + " [25] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091" + ] + } + ], + "source": [ + "Flux.train!(loss, params(m), train, opt, cb = evalcb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.5.0", + "language": "julia", + "name": "julia-1.5" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.5.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/vision/VGG/Compositional Pattern Network/Manifest.toml b/vision/VGG/Compositional Pattern Network/Manifest.toml new file mode 100644 index 000000000..5203234cc --- /dev/null +++ b/vision/VGG/Compositional Pattern Network/Manifest.toml @@ -0,0 +1,528 @@ +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "ec61a16eed883ad0cfa002d7489b3ce6d039bb9a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.4.0" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "fb86fe40cb5b35990e368709bfdc1b46dbb99dac" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.1.1" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "c49ec69428ffea0c1d1bbdc63d1a70f5df5860ad" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.7" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "cc0b3a248448d6ebecca4d1588c8fd54b96c5939" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.0" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "b91250044374764e7c29af59a774c4b8d6100b6e" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.1" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "f5ca23a08397288924a7535cd898d8ccbcde5ba5" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.2.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "5e7b1f49c80541860e08a7ea91805a24c1641f19" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.3" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "9bb70bff423fb26b45817da5f127d71e662bfe50" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.2" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "e8763955937114ea15cf3bfb5ae00588e19b58c3" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.5.2" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "18ae1c0a8df31549a9452ceac93751d4aa166071" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.1" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "01291372b2c3a67191a8cc2ff291f33f5485ac8b" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.0" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["LinearAlgebra", "Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "1ec5b78dbfb5ae2b3d7a4987a9287fed4cc31ded" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.1" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "adc26d2ee85a49c413464110d922cf21efc9d233" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.3.1" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "7d1442cb06fbfbc4fea936c3c56b38daffd22d3b" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.9.1" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "40f63689787ad81cd014361405997b78a5595944" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.9.2" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/VGG/Compositional Pattern Network/Project.toml b/vision/VGG/Compositional Pattern Network/Project.toml new file mode 100644 index 000000000..5a4b19ee1 --- /dev/null +++ b/vision/VGG/Compositional Pattern Network/Project.toml @@ -0,0 +1,3 @@ +[deps] +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" diff --git a/vision/VGG/Compositional Pattern Network/README.md b/vision/VGG/Compositional Pattern Network/README.md new file mode 100644 index 000000000..00b08a6ba --- /dev/null +++ b/vision/VGG/Compositional Pattern Network/README.md @@ -0,0 +1,5 @@ +# Generating Abstract Patterns with Compositional Pattern Producing Network + +- [Link to post](https://blog.otoro.net/2016/03/25/generating-abstract-patterns-with-tensorflow/) + + diff --git a/vision/VGG/Compositional Pattern Network/cppn.ipynb b/vision/VGG/Compositional Pattern Network/cppn.ipynb new file mode 100644 index 000000000..d3f14dbab --- /dev/null +++ b/vision/VGG/Compositional Pattern Network/cppn.ipynb @@ -0,0 +1,285 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "using Images\n", + "using Flux" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "262144" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "z_dim = 2\n", + "x_dim = 512\n", + "y_dim = 512\n", + "N = 14\n", + "hidden = 9\n", + "batch_size = 1024\n", + "n = x_dim * y_dim" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## cast 0:x-1 to -0.5:0.5" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "cast (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "\n", + "cast(x) = [range(-0.5, stop=0.5, step=1/(x - 1))...]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "262144-element Array{Float64,1}:\n 0.7071067811865476\n 0.7057243672141199\n 0.7043446771602189\n 0.702967727063262\n 0.7015935330555991\n 0.7002221113638016\n 0.6988534783089481\n 0.6974876503069023\n 0.6961246438685855\n 0.6947644756002421\n 0.6934071622036989\n 0.6920527204766176\n 0.6907011673127395\n ⋮\n 0.6920527204766176\n 0.6934071622036989\n 0.6947644756002421\n 0.6961246438685855\n 0.6974876503069023\n 0.6988534783089481\n 0.7002221113638016\n 0.7015935330555991\n 0.702967727063262\n 0.7043446771602189\n 0.7057243672141199\n 0.7071067811865476" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "xs, ys = cast(x_dim), cast(y_dim)\n", + "xs = repeat(xs, inner=(y_dim))\n", + "ys = repeat(ys, outer=(x_dim))\n", + "rs = sqrt.(xs.^2 + ys.^2)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "unit (generic function with 4 methods)" + }, + "metadata": {}, + "execution_count": 45 + } + ], + "source": [ + "unit(in=N, out=N, f=tanh) = Dense(in, out, f, initW=randn)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "11-element Array{Any,1}:\n Dense(5, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 14, tanh)\n Dense(14, 1, σ)" + }, + "metadata": {}, + "execution_count": 46 + } + ], + "source": [ + "layers = Any[unit(3 + z_dim), [unit() for _ in 1:hidden]..., unit(N, 1, σ)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- In essence, CPPN is just a function, c = f(x, y), that defines the intensity of the image for every point in space." + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getColorAt (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 47 + } + ], + "source": [ + "model = Chain(layers...)\n", + "getColorAt(x) = Flux.data(model(x))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Make batches from the data" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "batch (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 48 + } + ], + "source": [ + "function batch(arr, s)\n", + " l = size(arr, 2)\n", + " batches = [arr[:, i:min(i+s-1, l)] for i=1:s:l]\n", + " batches\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create image with intensities" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getImage (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 49 + } + ], + "source": [ + "function getImage(z)\n", + " z = repeat(reshape(z, 1, z_dim), outer=(n, 1))\n", + " coords = hcat(xs, ys, rs, z)'\n", + " coords = batch(coords, batch_size)\n", + " pixels = [Gray.(hcat(getColorAt.(coords)...))...]\n", + " reshape(pixels, y_dim, x_dim)\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "saveImg (generic function with 2 methods)" + }, + "metadata": {}, + "execution_count": 50 + } + ], + "source": [ + "function saveImg(z, image_path=\"sample.png\")\n", + " imgg = getImage(z)\n", + " save(image_path, imgg)\n", + " imgg\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Will generate at random everytime" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10-element Array{Array{Gray{Float64},2},1}:\n [Gray{Float64}(0.5946810419058337) Gray{Float64}(0.5844071218782684) … Gray{Float64}(0.15290018571840844) Gray{Float64}(0.15713981219146686); Gray{Float64}(0.6045090537341339) Gray{Float64}(0.5949466340725956) … Gray{Float64}(0.14036278476817127) Gray{Float64}(0.1443107836337645); … ; Gray{Float64}(0.24997947367144818) Gray{Float64}(0.3941396770541056) … Gray{Float64}(0.9202468729908154) Gray{Float64}(0.9346036508108042); Gray{Float64}(0.322760625913554) Gray{Float64}(0.419712705310896) … Gray{Float64}(0.9263213744240756) Gray{Float64}(0.9397232772490718)]\n [Gray{Float64}(0.11819501133927904) Gray{Float64}(0.11675908787762) … Gray{Float64}(0.7648690894451594) Gray{Float64}(0.7641494669450892); Gray{Float64}(0.11122510245225029) Gray{Float64}(0.10999837637012912) … Gray{Float64}(0.7760557634698783) Gray{Float64}(0.7774299862906915); … ; Gray{Float64}(0.9884111268623222) Gray{Float64}(0.9878463147302998) … Gray{Float64}(0.040437062420612985) Gray{Float64}(0.040251734266504434); Gray{Float64}(0.9884330525895296) Gray{Float64}(0.987905539429019) … Gray{Float64}(0.040855481496096094) Gray{Float64}(0.040774286483127704)]\n [Gray{Float64}(0.30111332470639385) Gray{Float64}(0.36931233674515107) … Gray{Float64}(0.9802169034653367) Gray{Float64}(0.980004397204283); Gray{Float64}(0.30198454950502784) Gray{Float64}(0.3265565045763157) … Gray{Float64}(0.9783248361872814) Gray{Float64}(0.9780989557593958); … ; Gray{Float64}(0.9870886870343462) Gray{Float64}(0.9867567536711443) … Gray{Float64}(0.13938127358070224) Gray{Float64}(0.1397740669694261); Gray{Float64}(0.9876162740565131) Gray{Float64}(0.9870729933165118) … Gray{Float64}(0.1394965721555591) Gray{Float64}(0.13991613416421314)]\n [Gray{Float64}(0.9973447963359813) Gray{Float64}(0.997383623223014) … Gray{Float64}(0.808199414391733) Gray{Float64}(0.8062856555648144); Gray{Float64}(0.9972773247520194) Gray{Float64}(0.9973201256078482) … Gray{Float64}(0.8173400212101277) Gray{Float64}(0.8154669108408432); … ; Gray{Float64}(0.14277984746933867) Gray{Float64}(0.1401673145569529) … Gray{Float64}(0.9820610565946315) Gray{Float64}(0.9861721958463162); Gray{Float64}(0.137213528249731) Gray{Float64}(0.14784284205637116) … Gray{Float64}(0.9782245631284652) Gray{Float64}(0.9836852366385818)]\n [Gray{Float64}(0.5280506047038377) Gray{Float64}(0.5296275960193153) … Gray{Float64}(0.21844161164706746) Gray{Float64}(0.21792058018356017); Gray{Float64}(0.5289058601233677) Gray{Float64}(0.530437210925873) … Gray{Float64}(0.21677907275196628) Gray{Float64}(0.2162595974529549); … ; Gray{Float64}(0.5322501889696164) Gray{Float64}(0.4973627768129481) … Gray{Float64}(0.15019248803392207) Gray{Float64}(0.12322683166948917); Gray{Float64}(0.5035340359632582) Gray{Float64}(0.4611392659481996) … Gray{Float64}(0.17010823449705706) Gray{Float64}(0.15265725701766789)]\n [Gray{Float64}(0.9978572825779828) Gray{Float64}(0.997784162879517) … Gray{Float64}(0.7923563110546755) Gray{Float64}(0.7298367585811415); Gray{Float64}(0.9977580158444547) Gray{Float64}(0.9976035272703733) … Gray{Float64}(0.19749284720224836) Gray{Float64}(0.15161258667570607); … ; Gray{Float64}(0.5844857482501201) Gray{Float64}(0.5702894093419769) … Gray{Float64}(0.06736554935132213) Gray{Float64}(0.07106875259503888); Gray{Float64}(0.5837236207932673) Gray{Float64}(0.5684540709659316) … Gray{Float64}(0.0720502989878908) Gray{Float64}(0.07644867913737839)]\n [Gray{Float64}(0.6237526395887424) Gray{Float64}(0.6269262963671303) … Gray{Float64}(0.1311215870642958) Gray{Float64}(0.13080990703261483); Gray{Float64}(0.6249924675099126) Gray{Float64}(0.628182141095554) … Gray{Float64}(0.12917766592287983) Gray{Float64}(0.1288833608702311); … ; Gray{Float64}(0.5084924250807725) Gray{Float64}(0.5082864547802465) … Gray{Float64}(0.3460909858668719) Gray{Float64}(0.3576344073773565); Gray{Float64}(0.5075344857806848) Gray{Float64}(0.5073312351345307) … Gray{Float64}(0.33777870691268463) Gray{Float64}(0.3482836434388344)]\n [Gray{Float64}(0.15008242040718592) Gray{Float64}(0.1561357486320554) … Gray{Float64}(0.03335540918013374) Gray{Float64}(0.03304361810872566); Gray{Float64}(0.15143073863591036) Gray{Float64}(0.15749410714776818) … Gray{Float64}(0.03451512808311513) Gray{Float64}(0.03415860613846207); … ; Gray{Float64}(0.028314124734372618) Gray{Float64}(0.028239552033001606) … Gray{Float64}(0.21148328958296184) Gray{Float64}(0.2085265164746206); Gray{Float64}(0.028281831284618444) Gray{Float64}(0.02821503723013225) … Gray{Float64}(0.21281683756288636) Gray{Float64}(0.20985201055606217)]\n [Gray{Float64}(0.539654439429861) Gray{Float64}(0.5586826490751261) … Gray{Float64}(0.33642858386966107) Gray{Float64}(0.32643899480548); Gray{Float64}(0.5426006347040554) Gray{Float64}(0.5612857381321137) … Gray{Float64}(0.3292006707085808) Gray{Float64}(0.318313229943188); … ; Gray{Float64}(0.5707348756442485) Gray{Float64}(0.6225053536183021) … Gray{Float64}(0.18327159657513448) Gray{Float64}(0.1994099221586931); Gray{Float64}(0.6085782839747482) Gray{Float64}(0.6598773551387486) … Gray{Float64}(0.16924592246131395) Gray{Float64}(0.18735413296904374)]\n [Gray{Float64}(0.27517661584805075) Gray{Float64}(0.2780619461164357) … Gray{Float64}(0.04551957533645665) Gray{Float64}(0.04482568087452583); Gray{Float64}(0.2767982452416591) Gray{Float64}(0.2796918739811609) … Gray{Float64}(0.04651389969453936) Gray{Float64}(0.045841702214116466); … ; Gray{Float64}(0.9464773358640313) Gray{Float64}(0.9458535612675792) … Gray{Float64}(0.3541721646132875) Gray{Float64}(0.34256547573330265); Gray{Float64}(0.9458198498460076) Gray{Float64}(0.9458341907119691) … Gray{Float64}(0.354674401855659) Gray{Float64}(0.3437442242037584)]", + "text/html": "
(a vector displayed as a row to save space)
" + }, + "metadata": {}, + "execution_count": 51 + } + ], + "source": [ + "[saveImg(rand(z_dim)) for _ in 1:10]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/VGG/Compositional Pattern Network/cppn.jl b/vision/VGG/Compositional Pattern Network/cppn.jl new file mode 100644 index 000000000..68528a150 --- /dev/null +++ b/vision/VGG/Compositional Pattern Network/cppn.jl @@ -0,0 +1,84 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% +using Images +using Flux + + +# %% +z_dim = 2 +x_dim = 512 +y_dim = 512 +N = 14 +hidden = 9 +batch_size = 1024 +n = x_dim * y_dim + + +# %% +# cast 0:x-1 to -0.5:0.5 +cast(x) = [range(-0.5, stop=0.5, step=1/(x - 1))...] + + +# %% +xs, ys = cast(x_dim), cast(y_dim) +xs = repeat(xs, inner=(y_dim)) +ys = repeat(ys, outer=(x_dim)) +rs = sqrt.(xs.^2 + ys.^2) + + +# %% +unit(in=N, out=N, f=tanh) = Dense(in, out, f, initW=randn) + + +# %% +layers = Any[unit(3 + z_dim), [unit() for _ in 1:hidden]..., unit(N, 1, σ)] + +# %% [markdown] +# - In essence, CPPN is just a function, c = f(x, y), that defines the intensity of the image for every point in space. + +# %% +model = Chain(layers...) +getColorAt(x) = Flux.data(model(x)) + +# %% [markdown] +# ## Make batches from the data + +# %% +function batch(arr, s) + l = size(arr, 2) + batches = [arr[:, i:min(i+s-1, l)] for i=1:s:l] + batches +end + +# %% [markdown] +# ## Create image with intensities + +# %% +function getImage(z) + z = repeat(reshape(z, 1, z_dim), outer=(n, 1)) + coords = hcat(xs, ys, rs, z)' + coords = batch(coords, batch_size) + pixels = [Gray.(hcat(getColorAt.(coords)...))...] + reshape(pixels, y_dim, x_dim) +end + + +# %% +function saveImg(z, image_path="sample.png") + imgg = getImage(z) + save(image_path, imgg) + imgg +end + +# %% [markdown] +# ## Will generate at random everytime + +# %% +saveImg(rand(z_dim)) + + +# %% + + + diff --git a/vision/cifar10/Manifest.toml b/vision/VGG/Manifest.toml similarity index 100% rename from vision/cifar10/Manifest.toml rename to vision/VGG/Manifest.toml diff --git a/vision/VGG/Multi Layer Perceptron/Manifest.toml b/vision/VGG/Multi Layer Perceptron/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/VGG/Multi Layer Perceptron/Manifest.toml @@ -0,0 +1,582 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/VGG/Multi Layer Perceptron/Project.toml b/vision/VGG/Multi Layer Perceptron/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/VGG/Multi Layer Perceptron/Project.toml @@ -0,0 +1,8 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/VGG/Multi Layer Perceptron/README.md b/vision/VGG/Multi Layer Perceptron/README.md new file mode 100644 index 000000000..4ea3069f7 --- /dev/null +++ b/vision/VGG/Multi Layer Perceptron/README.md @@ -0,0 +1,3 @@ +# A simple MLP + +- A good place to start with Deep Learning using Flux \ No newline at end of file diff --git a/vision/VGG/Multi Layer Perceptron/mlp.ipynb b/vision/VGG/Multi Layer Perceptron/mlp.ipynb new file mode 100644 index 000000000..1772c9f66 --- /dev/null +++ b/vision/VGG/Multi Layer Perceptron/mlp.ipynb @@ -0,0 +1,275 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "using Flux, Flux.Data.MNIST, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated\n", + "using CuArrays" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Classify MNIST digits with a simple multi-layer-perceptron\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "60000-element Array{Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},1}:\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n ⋮\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]\n [Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); … ; Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0); Gray{N0f8}(0.0) Gray{N0f8}(0.0) … Gray{N0f8}(0.0) Gray{N0f8}(0.0)]" + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "imgs = MNIST.images()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Stack images into one large batch" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "60000-element Array{Int64,1}:\n 5\n 0\n 4\n 1\n 9\n 2\n 1\n 3\n 1\n 4\n 3\n 5\n 3\n ⋮\n 7\n 8\n 9\n 2\n 9\n 5\n 1\n 8\n 3\n 5\n 6\n 8" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "\n", + "X = hcat(float.(reshape.(imgs, :))...) |> gpu\n", + "\n", + "labels = MNIST.labels()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# One-hot-encode the labels" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10×60000 Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}:\n 0 1 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0\n 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0\n 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 1 0 0 0 0 0 0 0 0 0 0 1 0 … 0 0 0 0 0 1 0 0 0 1 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1\n 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0" + }, + "metadata": {}, + "execution_count": 5 + }, + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`\n└ @ GPUArrays /home/subhaditya/.julia/packages/GPUArrays/JqOUg/src/host/indexing.jl:43\n" + } + ], + "source": [ + "\n", + "Y = onehotbatch(labels, 0:9) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain(Dense(784, 32, relu), Dense(32, 10), softmax)" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "\n", + "m = Chain(\n", + " Dense(28^2, 32, relu),\n", + " Dense(32, 10),\n", + " softmax) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "loss (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "\n", + "loss(x, y) = crossentropy(m(x), y)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "accuracy (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "\n", + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "\n", + "dataset = repeated((X, Y), 200)\n", + "evalcb = () -> @show(loss(X, Y))\n", + "opt = ADAM()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Train" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "loss(X, Y) = 2.2866402f0\n" + } + ], + "source": [ + "\n", + "Flux.train!(loss, params(m), dataset, opt, cb = throttle(evalcb, 10))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "accuracy(X, Y)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Test set accuracy\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tX = hcat(float.(reshape.(MNIST.images(:test), :))...) |> gpu\n", + "tY = onehotbatch(MNIST.labels(:test), 0:9) |> gpu\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "accuracy(tX, tY)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/VGG/Multi Layer Perceptron/mlp.jl b/vision/VGG/Multi Layer Perceptron/mlp.jl new file mode 100644 index 000000000..edd843690 --- /dev/null +++ b/vision/VGG/Multi Layer Perceptron/mlp.jl @@ -0,0 +1,88 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% +using Flux, Flux.Data.MNIST, Statistics +using Flux: onehotbatch, onecold, crossentropy, throttle +using Base.Iterators: repeated +using CuArrays + +# %% [markdown] +# # Classify MNIST digits with a simple multi-layer-perceptron +# + +# %% +imgs = MNIST.images() + +# %% [markdown] +# +# # Stack images into one large batch + +# %% + +X = hcat(float.(reshape.(imgs, :))...) |> gpu + +labels = MNIST.labels() + +# %% [markdown] +# # One-hot-encode the labels + +# %% + +Y = onehotbatch(labels, 0:9) |> gpu + + +# %% + +m = Chain( + Dense(28^2, 32, relu), + Dense(32, 10), + softmax) |> gpu + + +# %% + +loss(x, y) = crossentropy(m(x), y) + + +# %% + +accuracy(x, y) = mean(onecold(m(x)) .== onecold(y)) + + +# %% + +dataset = repeated((X, Y), 200) +evalcb = () -> @show(loss(X, Y)) +opt = ADAM() + +# %% [markdown] +# # Train + +# %% + +Flux.train!(loss, params(m), dataset, opt, cb = throttle(evalcb, 10)) + + +# %% + +accuracy(X, Y) + +# %% [markdown] +# +# # Test set accuracy +# + +# %% +tX = hcat(float.(reshape.(MNIST.images(:test), :))...) |> gpu +tY = onehotbatch(MNIST.labels(:test), 0:9) |> gpu + + +# %% + +accuracy(tX, tY) + + +# %% + + + diff --git a/vision/cifar10/Project.toml b/vision/VGG/Project.toml similarity index 69% rename from vision/cifar10/Project.toml rename to vision/VGG/Project.toml index 9c279df9e..403c36342 100644 --- a/vision/cifar10/Project.toml +++ b/vision/VGG/Project.toml @@ -1,4 +1,3 @@ [deps] -Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc" diff --git a/vision/VGG/README.md b/vision/VGG/README.md new file mode 100644 index 000000000..9ea3c1e21 --- /dev/null +++ b/vision/VGG/README.md @@ -0,0 +1,9 @@ +# VGG Models + +- This folder contains the Julia implementations of the VGG models +- The notebooks contain a running implementation you can open in Jupyter lab/notebook/colab etc +- The .jl files can be run directly using julia + + +- Simonyan, Karen, and Andrew Zisserman. "Very deep convolutional networks for large-scale image recognition." arXiv preprint arXiv:1409.1556 (2014). + [Paper](https://arxiv.org/pdf/1409.1556.pdf) diff --git a/vision/VGG/README.md~ b/vision/VGG/README.md~ new file mode 100644 index 000000000..48e6390f9 --- /dev/null +++ b/vision/VGG/README.md~ @@ -0,0 +1,3 @@ +# VGG Models + +This folder contains the Julia implementations of the VGG models diff --git a/vision/VGG/VGG16.ipynb b/vision/VGG/VGG16.ipynb new file mode 100644 index 000000000..e9d56b1f9 --- /dev/null +++ b/vision/VGG/VGG16.ipynb @@ -0,0 +1,432 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T22:10:02.179000+04:00", + "start_time": "2020-08-11T18:09:21.430Z" + }, + "scrolled": true, + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Precompiling Metalhead [dbeba491-748d-5e0e-a39e-b530a07fa0cc]\n└ @ Base loading.jl:1278\n" + } + ], + "source": [ + "using Flux, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated, partition\n", + "using Metalhead:trainimgs, CIFAR10\n", + "using Images" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T21:52:29.839000+04:00", + "start_time": "2020-08-11T17:52:25.688Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getarray (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CIFAR 10 dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T21:47:47.459000+04:00", + "start_time": "2020-08-11T17:47:47.448Z" + }, + "scrolled": true + }, + "outputs": [], + "source": [ + "X = trainimgs(CIFAR10)\n", + "imgs = [getarray(X[i].img) for i in 1:50000];\n", + "labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10);\n", + "train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]);" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:29:25.375000+04:00", + "start_time": "2020-08-11T12:28:59.367Z" + }, + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10×1000 Flux.OneHotMatrix{CUDA.CuArray{Flux.OneHotVector,1}}:\n 0 0 0 0 1 0 1 0 0 0 0 0 0 … 0 0 0 0 1 0 1 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1\n 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0\n 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 1 0 0 0 0 0 0 0 … 1 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0\n 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0" + }, + "metadata": {}, + "execution_count": 10 + }, + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`\n└ @ GPUArrays /home/subhaditya/.julia/packages/GPUArrays/PkHCM/src/host/indexing.jl:43\n" + } + ], + "source": [ + "valset = collect(49001:50000)\n", + "valX = cat(imgs[valset]..., dims = 4) |> gpu\n", + "valY = labels[:, valset] |> gpu" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## A block of Conv Relu Batchnorm based on input and output channels" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "conv_block (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "conv_block(in_channels, out_channels) = (\n", + " Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), \n", + " BatchNorm(out_channels))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Two of the conv blocks which is common in VGG + Maxpool" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "double_conv (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "double_conv(in_channels, out_channels) = (\n", + " conv_block(in_channels, out_channels)...,\n", + " conv_block(out_channels, out_channels)...,\n", + " MaxPool((2,2)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## VGG Arch\n", + "- ... operator will help us unroll the previously defined blocks" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "3-element Array{Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32}},1}:\n (Conv((3, 3), 256=>256, relu), BatchNorm(256))\n (Conv((3, 3), 256=>256, relu), BatchNorm(256))\n (Conv((3, 3), 256=>256, relu), BatchNorm(256))" + }, + "metadata": {}, + "execution_count": 29 + } + ], + "source": [ + "collect(Iterators.repeated(conv_block(256, 256),3))" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:05.168000+04:00", + "start_time": "2020-08-11T13:05:05.159Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "vgg16 (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 68 + } + ], + "source": [ + "vgg16(initial_channels, num_classes) = Chain(\n", + " double_conv(initial_channels, 64)...,\n", + " double_conv(64,128)...,\n", + " conv_block(128, 256)...,\n", + " double_conv(256, 256)..., \n", + " conv_block(256, 512)...,\n", + " double_conv(512, 512)...,\n", + " conv_block(512, 512)...,\n", + " double_conv(512, 512)...,\n", + " x -> reshape(x, :, size(x, 4)),\n", + " Dense(512, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, num_classes), \n", + " softmax\n", + " ) |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:08.454000+04:00", + "start_time": "2020-08-11T13:05:08.040Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain(Conv((3, 3), 3=>64, relu), BatchNorm(64), Conv((3, 3), 64=>64, relu), BatchNorm(64), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 64=>128, relu), BatchNorm(128), Conv((3, 3), 128=>128, relu), BatchNorm(128), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 128=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), Conv((3, 3), 256=>256, relu), BatchNorm(256), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 256=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), Conv((3, 3), 512=>512, relu), BatchNorm(512), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), #41, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" + }, + "metadata": {}, + "execution_count": 69 + } + ], + "source": [ + "m = vgg16(3, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:11.842000+04:00", + "start_time": "2020-08-11T13:05:11.839Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "loss (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 70 + } + ], + "source": [ + "loss(x, y) = crossentropy(m(x), y)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:12.481000+04:00", + "start_time": "2020-08-11T13:05:12.447Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "accuracy (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 71 + } + ], + "source": [ + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:13.807000+04:00", + "start_time": "2020-08-11T13:05:13.721Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "(::Flux.var\"#throttled#42\"{Flux.var\"#throttled#38#43\"{Bool,Bool,var\"#43#44\",Int64}}) (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 72 + } + ], + "source": [ + "evalcb = throttle(() -> @show(accuracy(valX, valY)), 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:05:14.409000+04:00", + "start_time": "2020-08-11T13:05:14.407Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + }, + "metadata": {}, + "execution_count": 73 + } + ], + "source": [ + "opt = ADAM()" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:07:16.455000+04:00", + "start_time": "2020-08-11T13:05:14.799Z" + } + }, + "outputs": [], + "source": [ + "Flux.train!(loss, params(m), train, opt, cb = evalcb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.5.0", + "language": "julia", + "name": "julia-1.5" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.5.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/vision/VGG/VGG16.jl b/vision/VGG/VGG16.jl new file mode 100644 index 000000000..a62fcac8e --- /dev/null +++ b/vision/VGG/VGG16.jl @@ -0,0 +1,104 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% [markdown] +#

Table of Contents

+#
+ +# %% +using Flux, Statistics +using Flux: onehotbatch, onecold, crossentropy, throttle +using Base.Iterators: repeated, partition +using Metalhead:trainimgs, CIFAR10 +using Images + + +# %% +getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1))) + +# %% [markdown] +# ## CIFAR 10 dataset + +# %% +X = trainimgs(CIFAR10) +imgs = [getarray(X[i].img) for i in 1:50000]; +labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10); +train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]); + + +# %% +valset = collect(49001:50000) +valX = cat(imgs[valset]..., dims = 4) |> gpu +valY = labels[:, valset] |> gpu + +# %% [markdown] +# ## A block of Conv Relu Batchnorm based on input and output channels + +# %% +conv_block(in_channels, out_channels) = ( + Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), + BatchNorm(out_channels)) + +# %% [markdown] +# ## Two of the conv blocks which is common in VGG + Maxpool + +# %% +double_conv(in_channels, out_channels) = ( + conv_block(in_channels, out_channels)..., + conv_block(out_channels, out_channels)..., + MaxPool((2,2))) + +# %% [markdown] +# ## VGG Arch +# - ... operator will help us unroll the previously defined blocks + +# %% + + +# %% +vgg16(initial_channels, num_classes) = Chain( + double_conv(initial_channels, 64)..., + double_conv(64,128)..., + conv_block(128, 256)..., + double_conv(256, 256)..., + conv_block(256, 512)..., + double_conv(512, 512)..., + conv_block(512, 512)..., + double_conv(512, 512)..., + x -> reshape(x, :, size(x, 4)), + Dense(512, 4096, relu), + Dropout(0.5), + Dense(4096, 4096, relu), + Dropout(0.5), + Dense(4096, num_classes), + softmax + ) |> gpu + + +# %% +m = vgg16(3, 10) + + +# %% +loss(x, y) = crossentropy(m(x), y) + + +# %% +accuracy(x, y) = mean(onecold(m(x)) .== onecold(y)) + + +# %% +evalcb = throttle(() -> @show(accuracy(valX, valY)), 10) + + +# %% +opt = ADAM() + + +# %% +Flux.train!(loss, params(m), train, opt, cb = evalcb) + + +# %% + + + diff --git a/vision/VGG/VGG19.ipynb b/vision/VGG/VGG19.ipynb new file mode 100644 index 000000000..e6cd24f28 --- /dev/null +++ b/vision/VGG/VGG19.ipynb @@ -0,0 +1,476 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.051Z" + }, + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Precompiling Flux [587475ba-b771-5e3f-ad9e-33799f191a9c]\n└ @ Base loading.jl:1278\n┌ Info: Precompiling Metalhead [dbeba491-748d-5e0e-a39e-b530a07fa0cc]\n└ @ Base loading.jl:1278\n" + } + ], + "source": [ + "using Flux, Statistics\n", + "using Flux: onehotbatch, onecold, crossentropy, throttle\n", + "using Base.Iterators: repeated, partition\n", + "using Metalhead:trainimgs, CIFAR10\n", + "using Images" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.691Z" + } + }, + "outputs": [], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:23.874Z" + } + }, + "outputs": [], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CIFAR 10 dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:24.076Z" + }, + "scrolled": true + }, + "outputs": [], + "source": [ + "X = trainimgs(CIFAR10)\n", + "imgs = [getarray(X[i].img) for i in 1:50000];\n", + "labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10);\n", + "train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:24.610Z" + } + }, + "outputs": [], + "source": [ + "valset = collect(49001:50000)\n", + "valX = cat(imgs[valset]..., dims = 4) |> gpu\n", + "valY = labels[:, valset] |> gpu" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## A block of Conv Relu Batchnorm based on input and output channels" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "ExecuteTime": { + "start_time": "2020-08-11T15:19:25.027Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "conv_block (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "conv_block(in_channels, out_channels) = (\n", + " Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), \n", + " BatchNorm(out_channels))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Two of the conv blocks which is common in VGG + Maxpool" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "double_conv (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "double_conv(in_channels, out_channels) = (\n", + " conv_block(in_channels, out_channels),\n", + " conv_block(out_channels, out_channels),\n", + " MaxPool((2,2)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Modified with 2 conv blocks, 1 conv and max pool" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "triple_conv (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "triple_conv(in_channels, out_channels) = (\n", + " conv_block(in_channels, out_channels),\n", + " conv_block(out_channels, out_channels),\n", + " Conv((3,3), out_channels => out_channels, relu, pad = (1,1), stride = (1,1)),\n", + " MaxPool((2,2)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## VGG\n", + "- ... operator will help us unroll the previously defined blocks" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "vgg19 (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "vgg19(initial_channels, num_classes) = Chain(\n", + " double_conv(initial_channels, 64)...,\n", + " double_conv(64, 128)...,\n", + " conv_block(128,256),\n", + " triple_conv(256,256)...,\n", + " conv_block(256,512),\n", + " triple_conv(512,512)...,\n", + " conv_block(512,512),\n", + " triple_conv(512,512)...,\n", + " x -> reshape(x, :, size(x, 4)),\n", + " Dense(512, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, 4096, relu),\n", + " Dropout(0.5),\n", + " Dense(4096, num_classes),\n", + " softmax) |> gpu" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:46.553000+04:00", + "start_time": "2020-08-11T13:14:45.389Z" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain((Conv((3, 3), 3=>64, relu), BatchNorm(64)), (Conv((3, 3), 64=>64, relu), BatchNorm(64)), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), (Conv((3, 3), 64=>128, relu), BatchNorm(128)), (Conv((3, 3), 128=>128, relu), BatchNorm(128)), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), (Conv((3, 3), 128=>256, relu), BatchNorm(256)), (Conv((3, 3), 256=>256, relu), BatchNorm(256)), (Conv((3, 3), 256=>256, relu), BatchNorm(256)), Conv((3, 3), 256=>256, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), (Conv((3, 3), 256=>512, relu), BatchNorm(512)), (Conv((3, 3), 512=>512, relu), BatchNorm(512)), (Conv((3, 3), 512=>512, relu), BatchNorm(512)), Conv((3, 3), 512=>512, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), (Conv((3, 3), 512=>512, relu), BatchNorm(512)), (Conv((3, 3), 512=>512, relu), BatchNorm(512)), (Conv((3, 3), 512=>512, relu), BatchNorm(512)), Conv((3, 3), 512=>512, relu), MaxPool((2, 2), pad = (0, 0, 0, 0), stride = (2, 2)), #3, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "m = vgg19(3, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.788000+04:00", + "start_time": "2020-08-11T13:14:47.786Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "loss (generic function with 1 method)" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "loss(x, y) = crossentropy(m(x), y)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.867000+04:00", + "start_time": "2020-08-11T13:14:47.866Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "accuracy (generic function with 1 method)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "accuracy(x, y) = mean(onecold(m(x)) .== onecold(y))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:14:47.990000+04:00", + "start_time": "2020-08-11T13:14:47.906Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#11#12\",Int64}}) (generic function with 1 method)" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "evalcb = throttle(() -> @show(accuracy(valX, valY)), 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:48.860000+04:00", + "start_time": "2020-08-11T13:13:19.436Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "opt = ADAM()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:16:10.370000+04:00", + "start_time": "2020-08-11T13:14:58.340Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "accuracy(valX, valY) = 0.119\n" + ] + }, + { + "ename": "LoadError", + "evalue": "InterruptException:", + "output_type": "error", + "traceback": [ + "InterruptException:", + "", + "Stacktrace:", + " [1] BatchNorm at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/normalise.jl:199 [inlined]", + " [2] _pullback(::Zygote.Context, ::BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [3] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [4] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [5] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [6] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [7] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [8] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [9] applychain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:36 [inlined]", + " [10] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [11] Chain at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/layers/basic.jl:38 [inlined]", + " [12] _pullback(::Zygote.Context, ::Chain{Tuple{Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},BatchNorm{typeof(identity),Array{Float32,1},Array{Float32,1},Float32},Conv{2,2,typeof(relu),Array{Float32,4},Array{Float32,1}},MaxPool{2,4},var\"#7#8\",Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(relu),Array{Float32,2},Array{Float32,1}},Dropout{Float64,Colon},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}},typeof(softmax)}}, ::Array{Float32,4}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [13] loss at ./In[17]:1 [inlined]", + " [14] _pullback(::Zygote.Context, ::typeof(loss), ::Array{Float32,4}, ::Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [15] adjoint at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/lib/lib.jl:179 [inlined]", + " [16] _pullback at /home/subhaditya/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]", + " [17] #17 at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:89 [inlined]", + " [18] _pullback(::Zygote.Context, ::Flux.Optimise.var\"#17#25\"{typeof(loss),Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}}}) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface2.jl:0", + " [19] pullback(::Function, ::Zygote.Params) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:172", + " [20] gradient(::Function, ::Zygote.Params) at /home/subhaditya/.julia/packages/Zygote/1GXzF/src/compiler/interface.jl:53", + " [21] macro expansion at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:88 [inlined]", + " [22] macro expansion at /home/subhaditya/.julia/packages/Juno/hEPx8/src/progress.jl:134 [inlined]", + " [23] train!(::typeof(loss), ::Zygote.Params, ::Array{Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}},1}, ::ADAM; cb::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#11#12\",Int64}}) at /home/subhaditya/.julia/packages/Flux/Fj3bt/src/optimise/train.jl:81", + " [24] top-level scope at In[21]:1", + " [25] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091" + ] + } + ], + "source": [ + "Flux.train!(loss, params(m), train, opt, cb = evalcb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.5.0", + "language": "julia", + "name": "julia-1.5" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.5.0" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": false, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": true, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/vision/VGG/VGG19.jl b/vision/VGG/VGG19.jl new file mode 100644 index 000000000..234f911a5 --- /dev/null +++ b/vision/VGG/VGG19.jl @@ -0,0 +1,114 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% [markdown] +#

Table of Contents

+#
+ +# %% +using Flux, Statistics +using Flux: onehotbatch, onecold, crossentropy, throttle +using Base.Iterators: repeated, partition +using Metalhead:trainimgs, CIFAR10 +using Images + + +# %% +using Flatten + + +# %% +getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1))) + +# %% [markdown] +# ## CIFAR 10 dataset + +# %% +X = trainimgs(CIFAR10) +imgs = [getarray(X[i].img) for i in 1:50000]; +labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10); +train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]); + + +# %% +valset = collect(49001:50000) +valX = cat(imgs[valset]..., dims = 4) |> gpu +valY = labels[:, valset] |> gpu + +# %% [markdown] +# ## A block of Conv Relu Batchnorm based on input and output channels + +# %% +conv_block(in_channels, out_channels) = ( + Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), + BatchNorm(out_channels)) + +# %% [markdown] +# ## Two of the conv blocks which is common in VGG + Maxpool + +# %% +double_conv(in_channels, out_channels) = ( + conv_block(in_channels, out_channels), + conv_block(out_channels, out_channels), + MaxPool((2,2))) + +# %% [markdown] +# ## Modified with 2 conv blocks, 1 conv and max pool + +# %% +triple_conv(in_channels, out_channels) = ( + conv_block(in_channels, out_channels), + conv_block(out_channels, out_channels), + Conv((3,3), out_channels => out_channels, relu, pad = (1,1), stride = (1,1)), + MaxPool((2,2))) + +# %% [markdown] +# ## VGG +# - ... operator will help us unroll the previously defined blocks + +# %% +vgg19(initial_channels, num_classes) = Chain( + double_conv(initial_channels, 64)..., + double_conv(64, 128)..., + conv_block(128,256), + triple_conv(256,256)..., + conv_block(256,512), + triple_conv(512,512)..., + conv_block(512,512), + triple_conv(512,512)..., + x -> reshape(x, :, size(x, 4)), + Dense(512, 4096, relu), + Dropout(0.5), + Dense(4096, 4096, relu), + Dropout(0.5), + Dense(4096, num_classes), + softmax) |> gpu + + +# %% +m = vgg19(3, 10) + + +# %% +loss(x, y) = crossentropy(m(x), y) + + +# %% +accuracy(x, y) = mean(onecold(m(x)) .== onecold(y)) + + +# %% +evalcb = throttle(() -> @show(accuracy(valX, valY)), 10) + + +# %% +opt = ADAM() + + +# %% +Flux.train!(loss, params(m), train, opt, cb = evalcb) + + +# %% + + + diff --git a/vision/VGG/Variational Auto Encoder/Manifest.toml b/vision/VGG/Variational Auto Encoder/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/VGG/Variational Auto Encoder/Manifest.toml @@ -0,0 +1,582 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/VGG/Variational Auto Encoder/Project.toml b/vision/VGG/Variational Auto Encoder/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/VGG/Variational Auto Encoder/Project.toml @@ -0,0 +1,8 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/VGG/Variational Auto Encoder/README.md b/vision/VGG/Variational Auto Encoder/README.md new file mode 100644 index 000000000..ce5a7edfe --- /dev/null +++ b/vision/VGG/Variational Auto Encoder/README.md @@ -0,0 +1,4 @@ +# Variational Auto Encoder + +- Kingma, D. P., & Welling, M. (2013). Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114. +- [Paper link](https://arxiv.org/pdf/1312.6114.pdf?source=post_page---------------------------) diff --git a/vision/VGG/Variational Auto Encoder/vae.ipynb b/vision/VGG/Variational Auto Encoder/vae.ipynb new file mode 100644 index 000000000..f04775d8e --- /dev/null +++ b/vision/VGG/Variational Auto Encoder/vae.ipynb @@ -0,0 +1,416 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "using Flux, Flux.Data.MNIST, Statistics, Flux.Optimise\n", + "using Flux: throttle, params\n", + "using Images\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initializing MNIST" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "784×60000 BitArray{2}:\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "X = (float.(hcat(vec.(MNIST.images())...)) .> 0.5) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "(60000, 100)" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "N, M = size(X, 2), 100" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "600-element Array{BitArray{2},1}:\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n ⋮\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "data = [X[:,i] for i in Iterators.partition(1:N,M)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Defining our network and parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "(Dense(784, 500, tanh), Dense(500, 5), Dense(500, 5))" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "Dz, Dh = 5, 500\n", + "A, μ, logσ = Dense(28^2, Dh, tanh) , Dense(Dh, Dz) , Dense(Dh, Dz) " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "g (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "g(X) = (h = A(X); (μ(h), logσ(h)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Sample latent space" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "sample_z (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "function sample_z(μ, logσ)\n", + " eps = randn(Float32, size(μ)) \n", + " return μ + exp.(logσ) .* eps\n", + "end\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain(Dense(5, 500, tanh), Dense(500, 784, σ))" + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "f = Chain(Dense(Dz, Dh, tanh), Dense(Dh, 28^2, σ))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# KL divergence and loss functions we need\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "kl_q_p (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "kl_q_p(μ, logσ) = 0.5f0 * sum(exp.(2f0 .* logσ) + μ.^2 .- 1f0 .+ logσ.^2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "logp_x_z (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "function logp_x_z(x, z)\n", + " p = f(z)\n", + " ll = x .* log.(p .+ eps(Float32)) + (1f0 .- x) .* log.(1 .- p .+ eps(Float32))\n", + " return sum(ll)\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "L̄ (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "L̄(X) = ((μ̂, logσ̂) = g(X); (logp_x_z(X, sample_z(μ̂, logσ̂)) - kl_q_p(μ̂, logσ̂)) * 1 // M)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "loss (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "loss(X) = -L̄(X) + 0.01f0 * sum(x->sum(x.^2), params(f))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Generate a sample\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "modelsample (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "function modelsample() \n", + " ϕ = zeros(Float32, Dz)\n", + " p = f(sample_z(ϕ, ϕ))\n", + " u = rand(Float32, size(p))\n", + " return (u .< p) \n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Train" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Params([Float32[-0.04325612 -0.04432942 … 0.024764992 0.0025093316; -0.06396034 0.0077259494 … -0.006176046 0.016506964; … ; 8.820455f-5 0.064784825 … 0.060753915 0.023969032; 0.009093919 0.05117704 … -0.0029312368 -0.05824799], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Float32[-0.00041203704 -0.0528699 … -0.03941686 0.06000133; 0.05124626 -0.06446281 … 0.0718011 -0.04769289; … ; -0.024800759 0.068491444 … 0.101761356 -0.07139413; 0.033019643 0.010317117 … -0.019728636 0.05537383], Float32[0.0, 0.0, 0.0, 0.0, 0.0], Float32[0.10620293 0.023587517 … 0.08458545 -0.020418482; -0.038067207 0.010741732 … 0.028195212 0.012534944; … ; -0.014529563 -0.087974004 … 0.028156698 0.045931697; -0.102924176 -0.032970604 … 0.029116375 0.035560943], Float32[0.0, 0.0, 0.0, 0.0, 0.0], Float32[-0.09521466 -0.08829451 … 0.020895256 0.0067901523; 0.108671494 -0.009676283 … 0.07440227 -0.0760235; … ; -0.0069366717 -0.011213775 … 0.06583009 0.10229878; 0.045926213 0.07811487 … 0.07023905 -0.10748437], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Float32[0.053993654 -0.0059612063 … 0.009265504 -0.062752746; 0.0022692461 -0.03440574 … 0.05393037 0.04595501; … ; 0.004562907 -0.043307588 … -0.004600816 0.041631848; -0.066888765 -0.032768432 … -0.036583245 0.010277884], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]])" + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "evalcb = throttle(() -> @show(-L̄(X[:, rand(1:N, M)])), 10)\n", + "opt = ADAM()\n", + "ps = params(A, μ, logσ, f)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Epoch 1\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 544.0159f0\n-(L̄(X[:, rand(1:N, M)])) = 188.8044f0\n-(L̄(X[:, rand(1:N, M)])) = 163.6948f0\n-(L̄(X[:, rand(1:N, M)])) = 170.76443f0\n-(L̄(X[:, rand(1:N, M)])) = 159.46655f0\n-(L̄(X[:, rand(1:N, M)])) = 168.12997f0\n-(L̄(X[:, rand(1:N, M)])) = 160.12689f0\n-(L̄(X[:, rand(1:N, M)])) = 165.35117f0\n-(L̄(X[:, rand(1:N, M)])) = 158.74713f0\n-(L̄(X[:, rand(1:N, M)])) = 156.7229f0\n┌ Info: Epoch 2\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 163.61983f0\n-(L̄(X[:, rand(1:N, M)])) = 161.33939f0\n-(L̄(X[:, rand(1:N, M)])) = 158.21996f0\n-(L̄(X[:, rand(1:N, M)])) = 151.2085f0\n-(L̄(X[:, rand(1:N, M)])) = 146.22623f0\n-(L̄(X[:, rand(1:N, M)])) = 150.20674f0\n-(L̄(X[:, rand(1:N, M)])) = 156.2229f0\n-(L̄(X[:, rand(1:N, M)])) = 143.83652f0\n┌ Info: Epoch 3\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 142.15207f0\n-(L̄(X[:, rand(1:N, M)])) = 142.52904f0\n-(L̄(X[:, rand(1:N, M)])) = 150.46121f0\n-(L̄(X[:, rand(1:N, M)])) = 148.28822f0\n-(L̄(X[:, rand(1:N, M)])) = 143.29193f0\n-(L̄(X[:, rand(1:N, M)])) = 139.69719f0\n-(L̄(X[:, rand(1:N, M)])) = 135.97562f0\n-(L̄(X[:, rand(1:N, M)])) = 142.71591f0\n-(L̄(X[:, rand(1:N, M)])) = 140.0783f0\n┌ Info: Epoch 4\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 139.62978f0\n-(L̄(X[:, rand(1:N, M)])) = 140.09804f0\n-(L̄(X[:, rand(1:N, M)])) = 140.85718f0\n-(L̄(X[:, rand(1:N, M)])) = 143.96771f0\n-(L̄(X[:, rand(1:N, M)])) = 139.85089f0\n-(L̄(X[:, rand(1:N, M)])) = 141.64473f0\n-(L̄(X[:, rand(1:N, M)])) = 136.50128f0\n-(L̄(X[:, rand(1:N, M)])) = 131.97739f0\n-(L̄(X[:, rand(1:N, M)])) = 129.70644f0\n┌ Info: Epoch 5\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 137.03206f0\n-(L̄(X[:, rand(1:N, M)])) = 142.41936f0\n-(L̄(X[:, rand(1:N, M)])) = 135.6215f0\n-(L̄(X[:, rand(1:N, M)])) = 139.77963f0\n-(L̄(X[:, rand(1:N, M)])) = 137.5791f0\n-(L̄(X[:, rand(1:N, M)])) = 129.35582f0\n-(L̄(X[:, rand(1:N, M)])) = 131.18831f0\n-(L̄(X[:, rand(1:N, M)])) = 128.95619f0\n┌ Info: Epoch 6\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 135.28596f0\n-(L̄(X[:, rand(1:N, M)])) = 133.43881f0\n-(L̄(X[:, rand(1:N, M)])) = 131.18222f0\n-(L̄(X[:, rand(1:N, M)])) = 130.74548f0\n-(L̄(X[:, rand(1:N, M)])) = 131.1535f0\n-(L̄(X[:, rand(1:N, M)])) = 136.14282f0\n-(L̄(X[:, rand(1:N, M)])) = 141.14491f0\n-(L̄(X[:, rand(1:N, M)])) = 130.80042f0\n-(L̄(X[:, rand(1:N, M)])) = 136.48291f0\n┌ Info: Epoch 7\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 129.31302f0\n-(L̄(X[:, rand(1:N, M)])) = 139.49428f0\n-(L̄(X[:, rand(1:N, M)])) = 130.39726f0\n-(L̄(X[:, rand(1:N, M)])) = 135.66624f0\n-(L̄(X[:, rand(1:N, M)])) = 139.52274f0\n-(L̄(X[:, rand(1:N, M)])) = 129.02013f0\n-(L̄(X[:, rand(1:N, M)])) = 132.18924f0\n-(L̄(X[:, rand(1:N, M)])) = 137.77753f0\n-(L̄(X[:, rand(1:N, M)])) = 137.5309f0\n┌ Info: Epoch 8\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 130.02092f0\n-(L̄(X[:, rand(1:N, M)])) = 127.53695f0\n-(L̄(X[:, rand(1:N, M)])) = 134.24876f0\n-(L̄(X[:, rand(1:N, M)])) = 126.24858f0\n-(L̄(X[:, rand(1:N, M)])) = 134.23547f0\n-(L̄(X[:, rand(1:N, M)])) = 128.36131f0\n-(L̄(X[:, rand(1:N, M)])) = 122.926f0\n┌ Info: Epoch 9\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 128.51785f0\n-(L̄(X[:, rand(1:N, M)])) = 130.70897f0\n-(L̄(X[:, rand(1:N, M)])) = 126.51974f0\n-(L̄(X[:, rand(1:N, M)])) = 126.55835f0\n-(L̄(X[:, rand(1:N, M)])) = 133.80797f0\n-(L̄(X[:, rand(1:N, M)])) = 137.55035f0\n-(L̄(X[:, rand(1:N, M)])) = 129.17249f0\n-(L̄(X[:, rand(1:N, M)])) = 133.11034f0\n-(L̄(X[:, rand(1:N, M)])) = 122.74662f0\n┌ Info: Epoch 10\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 129.06119f0\n-(L̄(X[:, rand(1:N, M)])) = 134.97176f0\n-(L̄(X[:, rand(1:N, M)])) = 125.834236f0\n-(L̄(X[:, rand(1:N, M)])) = 127.66348f0\n-(L̄(X[:, rand(1:N, M)])) = 125.22201f0\n-(L̄(X[:, rand(1:N, M)])) = 130.18465f0\n-(L̄(X[:, rand(1:N, M)])) = 128.43158f0\n-(L̄(X[:, rand(1:N, M)])) = 125.08065f0\n" + } + ], + "source": [ + "for i = 1:10\n", + " @info \"Epoch $i\"\n", + " Flux.train!(loss, ps, zip(data), opt, cb=evalcb)\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Outputs" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "28×280 Array{Gray{Bool},2} with eltype Gray{Bool}:\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n ⋮ ⋱ \n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAA4AQAAAADLRv+GAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAJCSURBVEjH7ZbNaiUhEIWF2hb4KoJbwVcX3Db4KkJvBac9pzrpCTeBSZxdXFwptT67fr3O/Y7f8b0hHVNw8mrzpYryt+zHSLMpPFd96u9XSPqb4in7/rhqE8bWZE58qmlkSJp5ZFJBD5yUOIlZ94aU604Mj+QzDsyQYosJNkFRh2E87U6c4jqrom4rJqxpdvL4vbnQ8diTIIFGBDrc48KUD6iTvQmTuekt/IaptMIifDIKvFBLxdHQln6WrZheIhQF3vUHzBilGJv5B0l7LxAocjVZvWzCDBqlPhYoFjraajIbgLnAuLtJVw86gUZtwqRL9RLzDOtQRN4Li+Daq/qeBd4hC2rBhdJgf7fy2YTpPHTmZjmGDGusAlzhJJpL6dqayYYUXNiLQWpXoeOYd7niU7sfa1HhaOmIvmiDgkP2ScyjbMQoS1IY22AR9sBZS3JmxYS+t7bB+rT+sgsz03lpqtK5WpmT6FAyJouSNw320vt6M21uxXh3MHByvDnukpYZIpX+o2/bCROVkbbKqNbuN2EiUuxqkDkwx4AJTEPr98LyZdkKrcicwqw7MXzhrgAz1N6MWo9I6Qnq1ks1Lil4e4MOrh59K8YvN/pSxgPDZ09cIiGabQwxO0Ozj5CyFeNWG8izcZ2+PCy57sFVPLpC4128v2IzBm/ovJOaq02fFAvu80GU+0B2ezHQnvG5Kpbi926x+8rbP069/8hVV7ZjPg79dEc+aAX3xfgxRj4FvGTL/8U495XP/mVswMjPEd/G/AEHtsT+spIneAAAAABJRU5ErkJggg==" + }, + "metadata": {}, + "execution_count": 21 + } + ], + "source": [ + "img(x) = Gray.(reshape(x, 28, 28))\n", + "sample = hcat(img.([modelsample() for i = 1:10])...)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "28×280 Array{Gray{Bool},2} with eltype Gray{Bool}:\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n ⋮ ⋱ \n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAA4AQAAAADLRv+GAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAJCSURBVEjH7ZbNaiUhEIWF2hb4KoJbwVcX3Db4KkJvBac9pzrpCTeBSZxdXFwptT67fr3O/Y7f8b0hHVNw8mrzpYryt+zHSLMpPFd96u9XSPqb4in7/rhqE8bWZE58qmlkSJp5ZFJBD5yUOIlZ94aU604Mj+QzDsyQYosJNkFRh2E87U6c4jqrom4rJqxpdvL4vbnQ8diTIIFGBDrc48KUD6iTvQmTuekt/IaptMIifDIKvFBLxdHQln6WrZheIhQF3vUHzBilGJv5B0l7LxAocjVZvWzCDBqlPhYoFjraajIbgLnAuLtJVw86gUZtwqRL9RLzDOtQRN4Li+Daq/qeBd4hC2rBhdJgf7fy2YTpPHTmZjmGDGusAlzhJJpL6dqayYYUXNiLQWpXoeOYd7niU7sfa1HhaOmIvmiDgkP2ScyjbMQoS1IY22AR9sBZS3JmxYS+t7bB+rT+sgsz03lpqtK5WpmT6FAyJouSNw320vt6M21uxXh3MHByvDnukpYZIpX+o2/bCROVkbbKqNbuN2EiUuxqkDkwx4AJTEPr98LyZdkKrcicwqw7MXzhrgAz1N6MWo9I6Qnq1ks1Lil4e4MOrh59K8YvN/pSxgPDZ09cIiGabQwxO0Ozj5CyFeNWG8izcZ2+PCy57sFVPLpC4128v2IzBm/ovJOaq02fFAvu80GU+0B2ezHQnvG5Kpbi926x+8rbP069/8hVV7ZjPg79dEc+aAX3xfgxRj4FvGTL/8U495XP/mVswMjPEd/G/AEHtsT+spIneAAAAABJRU5ErkJggg==" + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "sample" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "save(\"sample.png\", sample)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/VGG/Variational Auto Encoder/vae.jl b/vision/VGG/Variational Auto Encoder/vae.jl new file mode 100644 index 000000000..377ad40c9 --- /dev/null +++ b/vision/VGG/Variational Auto Encoder/vae.jl @@ -0,0 +1,99 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% +using Flux, Flux.Data.MNIST, Statistics, Flux.Optimise +using Flux: throttle, params +using Images + + +# %% +X = (float.(hcat(vec.(MNIST.images())...)) .> 0.5) + + +# %% +N, M = size(X, 2), 100 + + +# %% +data = [X[:,i] for i in Iterators.partition(1:N,M)] + + +# %% +Dz, Dh = 5, 500 +A, μ, logσ = Dense(28^2, Dh, tanh) , Dense(Dh, Dz) , Dense(Dh, Dz) + + +# %% +g(X) = (h = A(X); (μ(h), logσ(h))) + + +# %% +function sample_z(μ, logσ) + eps = randn(Float32, size(μ)) + return μ + exp.(logσ) .* eps +end + + +# %% +f = Chain(Dense(Dz, Dh, tanh), Dense(Dh, 28^2, σ)) + + +# %% +kl_q_p(μ, logσ) = 0.5f0 * sum(exp.(2f0 .* logσ) + μ.^2 .- 1f0 .+ logσ.^2) + + +# %% +function logp_x_z(x, z) + p = f(z) + ll = x .* log.(p .+ eps(Float32)) + (1f0 .- x) .* log.(1 .- p .+ eps(Float32)) + return sum(ll) +end + + +# %% +L̄(X) = ((μ̂, logσ̂) = g(X); (logp_x_z(X, sample_z(μ̂, logσ̂)) - kl_q_p(μ̂, logσ̂)) * 1 // M) + + +# %% +loss(X) = -L̄(X) + 0.01f0 * sum(x->sum(x.^2), params(f)) + + +# %% +function modelsample() + ϕ = zeros(Float32, Dz) + p = f(sample_z(ϕ, ϕ)) + u = rand(Float32, size(p)) + return (u .< p) +end + + +# %% +evalcb = throttle(() -> @show(-L̄(X[:, rand(1:N, M)])), 10) +opt = ADAM() +ps = params(A, μ, logσ, f) + + +# %% +for i = 1:10 + @info "Epoch $i" + Flux.train!(loss, ps, zip(data), opt, cb=evalcb) +end + + +# %% +img(x) = Gray.(reshape(x, 28, 28)) +sample = hcat(img.([modelsample() for i = 1:10])...) + + +# %% +sample + + +# %% +save("sample.png", sample) + + +# %% + + + diff --git a/vision/mnist/.gitignore b/vision/VGG/mnist/.gitignore similarity index 100% rename from vision/mnist/.gitignore rename to vision/VGG/mnist/.gitignore diff --git a/vision/VGG/mnist/Manifest.toml b/vision/VGG/mnist/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/VGG/mnist/Manifest.toml @@ -0,0 +1,582 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/VGG/mnist/Project.toml b/vision/VGG/mnist/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/VGG/mnist/Project.toml @@ -0,0 +1,8 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/mnist/autoencoder.jl b/vision/VGG/mnist/autoencoder.jl similarity index 100% rename from vision/mnist/autoencoder.jl rename to vision/VGG/mnist/autoencoder.jl diff --git a/vision/mnist/cuda/Manifest.toml b/vision/VGG/mnist/cuda/Manifest.toml similarity index 100% rename from vision/mnist/cuda/Manifest.toml rename to vision/VGG/mnist/cuda/Manifest.toml diff --git a/vision/mnist/cuda/Project.toml b/vision/VGG/mnist/cuda/Project.toml similarity index 100% rename from vision/mnist/cuda/Project.toml rename to vision/VGG/mnist/cuda/Project.toml diff --git a/vision/Variational Auto Encoder/Manifest.toml b/vision/Variational Auto Encoder/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/Variational Auto Encoder/Manifest.toml @@ -0,0 +1,582 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/Variational Auto Encoder/Project.toml b/vision/Variational Auto Encoder/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/Variational Auto Encoder/Project.toml @@ -0,0 +1,8 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/Variational Auto Encoder/README.md b/vision/Variational Auto Encoder/README.md new file mode 100644 index 000000000..ce5a7edfe --- /dev/null +++ b/vision/Variational Auto Encoder/README.md @@ -0,0 +1,4 @@ +# Variational Auto Encoder + +- Kingma, D. P., & Welling, M. (2013). Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114. +- [Paper link](https://arxiv.org/pdf/1312.6114.pdf?source=post_page---------------------------) diff --git a/vision/Variational Auto Encoder/vae.ipynb b/vision/Variational Auto Encoder/vae.ipynb new file mode 100644 index 000000000..f04775d8e --- /dev/null +++ b/vision/Variational Auto Encoder/vae.ipynb @@ -0,0 +1,416 @@ +{ + "metadata": { + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.2-final" + }, + "orig_nbformat": 2, + "kernelspec": { + "name": "julia-1.5", + "display_name": "Julia 1.5.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2, + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "using Flux, Flux.Data.MNIST, Statistics, Flux.Optimise\n", + "using Flux: throttle, params\n", + "using Images\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initializing MNIST" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n┌ Info: Downloading MNIST dataset\n└ @ Flux.Data.MNIST /home/subhaditya/.julia/packages/Flux/Fj3bt/src/data/mnist.jl:24\n" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "784×60000 BitArray{2}:\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "X = (float.(hcat(vec.(MNIST.images())...)) .> 0.5) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "(60000, 100)" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "N, M = size(X, 2), 100" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "600-element Array{BitArray{2},1}:\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n ⋮\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]\n [0 0 … 0 0; 0 0 … 0 0; … ; 0 0 … 0 0; 0 0 … 0 0]" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "data = [X[:,i] for i in Iterators.partition(1:N,M)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Defining our network and parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "(Dense(784, 500, tanh), Dense(500, 5), Dense(500, 5))" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "Dz, Dh = 5, 500\n", + "A, μ, logσ = Dense(28^2, Dh, tanh) , Dense(Dh, Dz) , Dense(Dh, Dz) " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "g (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "g(X) = (h = A(X); (μ(h), logσ(h)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Sample latent space" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "sample_z (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "function sample_z(μ, logσ)\n", + " eps = randn(Float32, size(μ)) \n", + " return μ + exp.(logσ) .* eps\n", + "end\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Chain(Dense(5, 500, tanh), Dense(500, 784, σ))" + }, + "metadata": {}, + "execution_count": 10 + } + ], + "source": [ + "f = Chain(Dense(Dz, Dh, tanh), Dense(Dh, 28^2, σ))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# KL divergence and loss functions we need\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "kl_q_p (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "kl_q_p(μ, logσ) = 0.5f0 * sum(exp.(2f0 .* logσ) + μ.^2 .- 1f0 .+ logσ.^2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "logp_x_z (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "function logp_x_z(x, z)\n", + " p = f(z)\n", + " ll = x .* log.(p .+ eps(Float32)) + (1f0 .- x) .* log.(1 .- p .+ eps(Float32))\n", + " return sum(ll)\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "L̄ (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "L̄(X) = ((μ̂, logσ̂) = g(X); (logp_x_z(X, sample_z(μ̂, logσ̂)) - kl_q_p(μ̂, logσ̂)) * 1 // M)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "loss (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "loss(X) = -L̄(X) + 0.01f0 * sum(x->sum(x.^2), params(f))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Generate a sample\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "modelsample (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "function modelsample() \n", + " ϕ = zeros(Float32, Dz)\n", + " p = f(sample_z(ϕ, ϕ))\n", + " u = rand(Float32, size(p))\n", + " return (u .< p) \n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Train" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Params([Float32[-0.04325612 -0.04432942 … 0.024764992 0.0025093316; -0.06396034 0.0077259494 … -0.006176046 0.016506964; … ; 8.820455f-5 0.064784825 … 0.060753915 0.023969032; 0.009093919 0.05117704 … -0.0029312368 -0.05824799], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Float32[-0.00041203704 -0.0528699 … -0.03941686 0.06000133; 0.05124626 -0.06446281 … 0.0718011 -0.04769289; … ; -0.024800759 0.068491444 … 0.101761356 -0.07139413; 0.033019643 0.010317117 … -0.019728636 0.05537383], Float32[0.0, 0.0, 0.0, 0.0, 0.0], Float32[0.10620293 0.023587517 … 0.08458545 -0.020418482; -0.038067207 0.010741732 … 0.028195212 0.012534944; … ; -0.014529563 -0.087974004 … 0.028156698 0.045931697; -0.102924176 -0.032970604 … 0.029116375 0.035560943], Float32[0.0, 0.0, 0.0, 0.0, 0.0], Float32[-0.09521466 -0.08829451 … 0.020895256 0.0067901523; 0.108671494 -0.009676283 … 0.07440227 -0.0760235; … ; -0.0069366717 -0.011213775 … 0.06583009 0.10229878; 0.045926213 0.07811487 … 0.07023905 -0.10748437], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], Float32[0.053993654 -0.0059612063 … 0.009265504 -0.062752746; 0.0022692461 -0.03440574 … 0.05393037 0.04595501; … ; 0.004562907 -0.043307588 … -0.004600816 0.041631848; -0.066888765 -0.032768432 … -0.036583245 0.010277884], Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]])" + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "evalcb = throttle(() -> @show(-L̄(X[:, rand(1:N, M)])), 10)\n", + "opt = ADAM()\n", + "ps = params(A, μ, logσ, f)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": "┌ Info: Epoch 1\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 544.0159f0\n-(L̄(X[:, rand(1:N, M)])) = 188.8044f0\n-(L̄(X[:, rand(1:N, M)])) = 163.6948f0\n-(L̄(X[:, rand(1:N, M)])) = 170.76443f0\n-(L̄(X[:, rand(1:N, M)])) = 159.46655f0\n-(L̄(X[:, rand(1:N, M)])) = 168.12997f0\n-(L̄(X[:, rand(1:N, M)])) = 160.12689f0\n-(L̄(X[:, rand(1:N, M)])) = 165.35117f0\n-(L̄(X[:, rand(1:N, M)])) = 158.74713f0\n-(L̄(X[:, rand(1:N, M)])) = 156.7229f0\n┌ Info: Epoch 2\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 163.61983f0\n-(L̄(X[:, rand(1:N, M)])) = 161.33939f0\n-(L̄(X[:, rand(1:N, M)])) = 158.21996f0\n-(L̄(X[:, rand(1:N, M)])) = 151.2085f0\n-(L̄(X[:, rand(1:N, M)])) = 146.22623f0\n-(L̄(X[:, rand(1:N, M)])) = 150.20674f0\n-(L̄(X[:, rand(1:N, M)])) = 156.2229f0\n-(L̄(X[:, rand(1:N, M)])) = 143.83652f0\n┌ Info: Epoch 3\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 142.15207f0\n-(L̄(X[:, rand(1:N, M)])) = 142.52904f0\n-(L̄(X[:, rand(1:N, M)])) = 150.46121f0\n-(L̄(X[:, rand(1:N, M)])) = 148.28822f0\n-(L̄(X[:, rand(1:N, M)])) = 143.29193f0\n-(L̄(X[:, rand(1:N, M)])) = 139.69719f0\n-(L̄(X[:, rand(1:N, M)])) = 135.97562f0\n-(L̄(X[:, rand(1:N, M)])) = 142.71591f0\n-(L̄(X[:, rand(1:N, M)])) = 140.0783f0\n┌ Info: Epoch 4\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 139.62978f0\n-(L̄(X[:, rand(1:N, M)])) = 140.09804f0\n-(L̄(X[:, rand(1:N, M)])) = 140.85718f0\n-(L̄(X[:, rand(1:N, M)])) = 143.96771f0\n-(L̄(X[:, rand(1:N, M)])) = 139.85089f0\n-(L̄(X[:, rand(1:N, M)])) = 141.64473f0\n-(L̄(X[:, rand(1:N, M)])) = 136.50128f0\n-(L̄(X[:, rand(1:N, M)])) = 131.97739f0\n-(L̄(X[:, rand(1:N, M)])) = 129.70644f0\n┌ Info: Epoch 5\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 137.03206f0\n-(L̄(X[:, rand(1:N, M)])) = 142.41936f0\n-(L̄(X[:, rand(1:N, M)])) = 135.6215f0\n-(L̄(X[:, rand(1:N, M)])) = 139.77963f0\n-(L̄(X[:, rand(1:N, M)])) = 137.5791f0\n-(L̄(X[:, rand(1:N, M)])) = 129.35582f0\n-(L̄(X[:, rand(1:N, M)])) = 131.18831f0\n-(L̄(X[:, rand(1:N, M)])) = 128.95619f0\n┌ Info: Epoch 6\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 135.28596f0\n-(L̄(X[:, rand(1:N, M)])) = 133.43881f0\n-(L̄(X[:, rand(1:N, M)])) = 131.18222f0\n-(L̄(X[:, rand(1:N, M)])) = 130.74548f0\n-(L̄(X[:, rand(1:N, M)])) = 131.1535f0\n-(L̄(X[:, rand(1:N, M)])) = 136.14282f0\n-(L̄(X[:, rand(1:N, M)])) = 141.14491f0\n-(L̄(X[:, rand(1:N, M)])) = 130.80042f0\n-(L̄(X[:, rand(1:N, M)])) = 136.48291f0\n┌ Info: Epoch 7\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 129.31302f0\n-(L̄(X[:, rand(1:N, M)])) = 139.49428f0\n-(L̄(X[:, rand(1:N, M)])) = 130.39726f0\n-(L̄(X[:, rand(1:N, M)])) = 135.66624f0\n-(L̄(X[:, rand(1:N, M)])) = 139.52274f0\n-(L̄(X[:, rand(1:N, M)])) = 129.02013f0\n-(L̄(X[:, rand(1:N, M)])) = 132.18924f0\n-(L̄(X[:, rand(1:N, M)])) = 137.77753f0\n-(L̄(X[:, rand(1:N, M)])) = 137.5309f0\n┌ Info: Epoch 8\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 130.02092f0\n-(L̄(X[:, rand(1:N, M)])) = 127.53695f0\n-(L̄(X[:, rand(1:N, M)])) = 134.24876f0\n-(L̄(X[:, rand(1:N, M)])) = 126.24858f0\n-(L̄(X[:, rand(1:N, M)])) = 134.23547f0\n-(L̄(X[:, rand(1:N, M)])) = 128.36131f0\n-(L̄(X[:, rand(1:N, M)])) = 122.926f0\n┌ Info: Epoch 9\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 128.51785f0\n-(L̄(X[:, rand(1:N, M)])) = 130.70897f0\n-(L̄(X[:, rand(1:N, M)])) = 126.51974f0\n-(L̄(X[:, rand(1:N, M)])) = 126.55835f0\n-(L̄(X[:, rand(1:N, M)])) = 133.80797f0\n-(L̄(X[:, rand(1:N, M)])) = 137.55035f0\n-(L̄(X[:, rand(1:N, M)])) = 129.17249f0\n-(L̄(X[:, rand(1:N, M)])) = 133.11034f0\n-(L̄(X[:, rand(1:N, M)])) = 122.74662f0\n┌ Info: Epoch 10\n└ @ Main In[17]:2\n-(L̄(X[:, rand(1:N, M)])) = 129.06119f0\n-(L̄(X[:, rand(1:N, M)])) = 134.97176f0\n-(L̄(X[:, rand(1:N, M)])) = 125.834236f0\n-(L̄(X[:, rand(1:N, M)])) = 127.66348f0\n-(L̄(X[:, rand(1:N, M)])) = 125.22201f0\n-(L̄(X[:, rand(1:N, M)])) = 130.18465f0\n-(L̄(X[:, rand(1:N, M)])) = 128.43158f0\n-(L̄(X[:, rand(1:N, M)])) = 125.08065f0\n" + } + ], + "source": [ + "for i = 1:10\n", + " @info \"Epoch $i\"\n", + " Flux.train!(loss, ps, zip(data), opt, cb=evalcb)\n", + "end" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Outputs" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "28×280 Array{Gray{Bool},2} with eltype Gray{Bool}:\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n ⋮ ⋱ \n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAA4AQAAAADLRv+GAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAJCSURBVEjH7ZbNaiUhEIWF2hb4KoJbwVcX3Db4KkJvBac9pzrpCTeBSZxdXFwptT67fr3O/Y7f8b0hHVNw8mrzpYryt+zHSLMpPFd96u9XSPqb4in7/rhqE8bWZE58qmlkSJp5ZFJBD5yUOIlZ94aU604Mj+QzDsyQYosJNkFRh2E87U6c4jqrom4rJqxpdvL4vbnQ8diTIIFGBDrc48KUD6iTvQmTuekt/IaptMIifDIKvFBLxdHQln6WrZheIhQF3vUHzBilGJv5B0l7LxAocjVZvWzCDBqlPhYoFjraajIbgLnAuLtJVw86gUZtwqRL9RLzDOtQRN4Li+Daq/qeBd4hC2rBhdJgf7fy2YTpPHTmZjmGDGusAlzhJJpL6dqayYYUXNiLQWpXoeOYd7niU7sfa1HhaOmIvmiDgkP2ScyjbMQoS1IY22AR9sBZS3JmxYS+t7bB+rT+sgsz03lpqtK5WpmT6FAyJouSNw320vt6M21uxXh3MHByvDnukpYZIpX+o2/bCROVkbbKqNbuN2EiUuxqkDkwx4AJTEPr98LyZdkKrcicwqw7MXzhrgAz1N6MWo9I6Qnq1ks1Lil4e4MOrh59K8YvN/pSxgPDZ09cIiGabQwxO0Ozj5CyFeNWG8izcZ2+PCy57sFVPLpC4128v2IzBm/ovJOaq02fFAvu80GU+0B2ezHQnvG5Kpbi926x+8rbP069/8hVV7ZjPg79dEc+aAX3xfgxRj4FvGTL/8U495XP/mVswMjPEd/G/AEHtsT+spIneAAAAABJRU5ErkJggg==" + }, + "metadata": {}, + "execution_count": 21 + } + ], + "source": [ + "img(x) = Gray.(reshape(x, 28, 28))\n", + "sample = hcat(img.([modelsample() for i = 1:10])...)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "28×280 Array{Gray{Bool},2} with eltype Gray{Bool}:\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n ⋮ ⋱ \n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) … Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)\n Gray{Bool}(false) Gray{Bool}(false) Gray{Bool}(false)", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAA4AQAAAADLRv+GAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAJCSURBVEjH7ZbNaiUhEIWF2hb4KoJbwVcX3Db4KkJvBac9pzrpCTeBSZxdXFwptT67fr3O/Y7f8b0hHVNw8mrzpYryt+zHSLMpPFd96u9XSPqb4in7/rhqE8bWZE58qmlkSJp5ZFJBD5yUOIlZ94aU604Mj+QzDsyQYosJNkFRh2E87U6c4jqrom4rJqxpdvL4vbnQ8diTIIFGBDrc48KUD6iTvQmTuekt/IaptMIifDIKvFBLxdHQln6WrZheIhQF3vUHzBilGJv5B0l7LxAocjVZvWzCDBqlPhYoFjraajIbgLnAuLtJVw86gUZtwqRL9RLzDOtQRN4Li+Daq/qeBd4hC2rBhdJgf7fy2YTpPHTmZjmGDGusAlzhJJpL6dqayYYUXNiLQWpXoeOYd7niU7sfa1HhaOmIvmiDgkP2ScyjbMQoS1IY22AR9sBZS3JmxYS+t7bB+rT+sgsz03lpqtK5WpmT6FAyJouSNw320vt6M21uxXh3MHByvDnukpYZIpX+o2/bCROVkbbKqNbuN2EiUuxqkDkwx4AJTEPr98LyZdkKrcicwqw7MXzhrgAz1N6MWo9I6Qnq1ks1Lil4e4MOrh59K8YvN/pSxgPDZ09cIiGabQwxO0Ozj5CyFeNWG8izcZ2+PCy57sFVPLpC4128v2IzBm/ovJOaq02fFAvu80GU+0B2ezHQnvG5Kpbi926x+8rbP069/8hVV7ZjPg79dEc+aAX3xfgxRj4FvGTL/8U495XP/mVswMjPEd/G/AEHtsT+spIneAAAAABJRU5ErkJggg==" + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "sample" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "save(\"sample.png\", sample)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/vision/Variational Auto Encoder/vae.jl b/vision/Variational Auto Encoder/vae.jl new file mode 100644 index 000000000..377ad40c9 --- /dev/null +++ b/vision/Variational Auto Encoder/vae.jl @@ -0,0 +1,99 @@ +# To add a new cell, type '# %%' +# To add a new markdown cell, type '# %% [markdown]' +# %% +using Flux, Flux.Data.MNIST, Statistics, Flux.Optimise +using Flux: throttle, params +using Images + + +# %% +X = (float.(hcat(vec.(MNIST.images())...)) .> 0.5) + + +# %% +N, M = size(X, 2), 100 + + +# %% +data = [X[:,i] for i in Iterators.partition(1:N,M)] + + +# %% +Dz, Dh = 5, 500 +A, μ, logσ = Dense(28^2, Dh, tanh) , Dense(Dh, Dz) , Dense(Dh, Dz) + + +# %% +g(X) = (h = A(X); (μ(h), logσ(h))) + + +# %% +function sample_z(μ, logσ) + eps = randn(Float32, size(μ)) + return μ + exp.(logσ) .* eps +end + + +# %% +f = Chain(Dense(Dz, Dh, tanh), Dense(Dh, 28^2, σ)) + + +# %% +kl_q_p(μ, logσ) = 0.5f0 * sum(exp.(2f0 .* logσ) + μ.^2 .- 1f0 .+ logσ.^2) + + +# %% +function logp_x_z(x, z) + p = f(z) + ll = x .* log.(p .+ eps(Float32)) + (1f0 .- x) .* log.(1 .- p .+ eps(Float32)) + return sum(ll) +end + + +# %% +L̄(X) = ((μ̂, logσ̂) = g(X); (logp_x_z(X, sample_z(μ̂, logσ̂)) - kl_q_p(μ̂, logσ̂)) * 1 // M) + + +# %% +loss(X) = -L̄(X) + 0.01f0 * sum(x->sum(x.^2), params(f)) + + +# %% +function modelsample() + ϕ = zeros(Float32, Dz) + p = f(sample_z(ϕ, ϕ)) + u = rand(Float32, size(p)) + return (u .< p) +end + + +# %% +evalcb = throttle(() -> @show(-L̄(X[:, rand(1:N, M)])), 10) +opt = ADAM() +ps = params(A, μ, logσ, f) + + +# %% +for i = 1:10 + @info "Epoch $i" + Flux.train!(loss, ps, zip(data), opt, cb=evalcb) +end + + +# %% +img(x) = Gray.(reshape(x, 28, 28)) +sample = hcat(img.([modelsample() for i = 1:10])...) + + +# %% +sample + + +# %% +save("sample.png", sample) + + +# %% + + + diff --git a/vision/cifar10/cifar10.jl b/vision/cifar10/cifar10.jl deleted file mode 100644 index 236aec358..000000000 --- a/vision/cifar10/cifar10.jl +++ /dev/null @@ -1,136 +0,0 @@ -using Flux, Metalhead, Statistics -using Flux: onehotbatch, onecold, crossentropy, throttle -using Metalhead: trainimgs -using Images: channelview -using Statistics: mean -using Base.Iterators: partition - -# VGG16 and VGG19 models - -vgg16() = Chain( - Conv((3, 3), 3 => 64, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(64), - Conv((3, 3), 64 => 64, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(64), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 64 => 128, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(128), - Conv((3, 3), 128 => 128, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(128), - x -> maxpool(x, (2,2)), - Conv((3, 3), 128 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 256 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - x -> maxpool(x, (2, 2)), - x -> reshape(x, :, size(x, 4)), - Dense(512, 4096, relu), - Dropout(0.5), - Dense(4096, 4096, relu), - Dropout(0.5), - Dense(4096, 10), - softmax) |> gpu - -vgg19() = Chain( - Conv((3, 3), 3 => 64, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(64), - Conv((3, 3), 64 => 64, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(64), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 64 => 128, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(128), - Conv((3, 3), 128 => 128, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(128), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 128 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(256), - Conv((3, 3), 256 => 256, relu, pad=(1, 1), stride=(1, 1)), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 256 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - x -> maxpool(x, (2, 2)), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - BatchNorm(512), - Conv((3, 3), 512 => 512, relu, pad=(1, 1), stride=(1, 1)), - x -> maxpool(x, (2, 2)), - x -> reshape(x, :, size(x, 4)), - Dense(512, 4096, relu), - Dropout(0.5), - Dense(4096, 4096, relu), - Dropout(0.5), - Dense(4096, 10), - softmax) |> gpu - -# Function to convert the RGB image to Float64 Arrays - -getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1))) - -# Fetching the train and validation data and getting them into proper shape - -X = trainimgs(CIFAR10) -imgs = [getarray(X[i].img) for i in 1:50000] -labels = onehotbatch([X[i].ground_truth.class for i in 1:50000],1:10) -train = gpu.([(cat(imgs[i]..., dims = 4), labels[:,i]) for i in partition(1:49000, 100)]) -valset = collect(49001:50000) -valX = cat(imgs[valset]..., dims = 4) |> gpu -valY = labels[:, valset] |> gpu - -# Defining the loss and accuracy functions - -m = vgg16() - -loss(x, y) = crossentropy(m(x), y) - -accuracy(x, y) = mean(onecold(m(x), 1:10) .== onecold(y, 1:10)) - -# Defining the callback and the optimizer - -evalcb = throttle(() -> @show(accuracy(valX, valY)), 10) - -opt = ADAM() - -# Starting to train models - -Flux.train!(loss, params(m), train, opt, cb = evalcb) - -# Fetch the test data from Metalhead and get it into proper shape. -# CIFAR-10 does not specify a validation set so valimgs fetch the testdata instead of testimgs - -test = valimgs(CIFAR10) - -testimgs = [getarray(test[i].img) for i in 1:10000] -testY = onehotbatch([test[i].ground_truth.class for i in 1:10000], 1:10) |> gpu -testX = cat(testimgs..., dims = 4) |> gpu - -# Print the final accuracy - -@show(accuracy(testX, testY)) diff --git a/vision/cppn/sample.png b/vision/cppn/sample.png deleted file mode 100644 index 6b7726f25..000000000 Binary files a/vision/cppn/sample.png and /dev/null differ diff --git a/vision/cuda/Manifest.toml b/vision/cuda/Manifest.toml new file mode 100644 index 000000000..a0ba0c673 --- /dev/null +++ b/vision/cuda/Manifest.toml @@ -0,0 +1,624 @@ +# This file is machine-generated - editing it directly is not advised + +[[AbstractFFTs]] +deps = ["Compat", "LinearAlgebra"] +git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "0.3.2" + +[[AbstractTrees]] +deps = ["Markdown", "Test"] +git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +version = "0.2.1" + +[[Adapt]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "53d8fec4f662088c1202530e338a11a919407f3b" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "0.4.2" + +[[Arpack]] +deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f" +uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97" +version = "0.3.0" + +[[AxisAlgorithms]] +deps = ["Compat", "WoodburyMatrices"] +git-tree-sha1 = "99dabbe853e4f641ab21a676131f2cf9fb29937e" +uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950" +version = "0.3.0" + +[[AxisArrays]] +deps = ["Compat", "Dates", "IntervalSets", "IterTools", "Random", "RangeArrays", "Test"] +git-tree-sha1 = "2e2536e9e6f27c4f8d09d8442b61a7ae0b910c28" +uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9" +version = "0.3.0" + +[[BSON]] +deps = ["Test"] +git-tree-sha1 = "922b43e731601b73f0e53f1cc94ea719b94f673a" +uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +version = "0.2.1" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[BinDeps]] +deps = ["Compat", "Libdl", "SHA", "URIParser"] +git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9" +uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee" +version = "0.8.10" + +[[BinaryProvider]] +deps = ["Libdl", "Pkg", "SHA", "Test"] +git-tree-sha1 = "055eb2690182ebc31087859c3dd8598371d3ef9e" +uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" +version = "0.5.3" + +[[CUDAapi]] +deps = ["Libdl", "Logging", "Test"] +git-tree-sha1 = "350cde12f25d297609369a9acb4c6214211675db" +uuid = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3" +version = "0.5.4" + +[[CUDAdrv]] +deps = ["CUDAapi", "Libdl", "Printf", "Test"] +git-tree-sha1 = "dfe527ba231b6b699f879d1d384c1d39b49fc005" +uuid = "c5f51814-7f29-56b8-a69c-e4d8f6be1fde" +version = "1.0.1" + +[[CUDAnative]] +deps = ["Adapt", "CUDAapi", "CUDAdrv", "InteractiveUtils", "LLVM", "Libdl", "Pkg", "Printf", "Statistics", "Test"] +git-tree-sha1 = "92e3ec4f4458e43cc17be4388b68690dbef24f31" +uuid = "be33ccc6-a3ff-5ff2-a52e-74243cff1e17" +version = "1.0.1" + +[[CatIndices]] +deps = ["CustomUnitRanges", "OffsetArrays", "Test"] +git-tree-sha1 = "254cf73ea369d2e39bfd6c5eb27a2296cfaed68c" +uuid = "aafaddc9-749c-510e-ac4f-586e18779b91" +version = "0.2.0" + +[[CodecZlib]] +deps = ["BinaryProvider", "Libdl", "Test", "TranscodingStreams"] +git-tree-sha1 = "e3df104c84dfc108f0ca203fd7f5bbdc98641ae9" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.5.1" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random", "Test"] +git-tree-sha1 = "f73b0e10f2a5756de7019818a41654686da06b09" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.7.5" + +[[ColorVectorSpace]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "StatsBase", "Test"] +git-tree-sha1 = "a890f08e61b40e9843d7177206da61229a3603c8" +uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" +version = "0.6.2" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Printf", "Reexport", "Test"] +git-tree-sha1 = "9f0a0210450acb91c730b730a994f8eef1d3d543" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.9.5" + +[[CommonSubexpressions]] +deps = ["Test"] +git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.2.0" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "49269e311ffe11ac5b334681d212329002a9832a" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "1.5.1" + +[[ComputationalResources]] +deps = ["Test"] +git-tree-sha1 = "89e7e7ed20af73d9f78877d2b8d1194e7b6ff13d" +uuid = "ed09eef8-17a6-5b46-8889-db040fac31e3" +version = "0.3.0" + +[[Conda]] +deps = ["Compat", "JSON", "VersionParsing"] +git-tree-sha1 = "b625d802587c2150c279a40a646fba63f9bd8187" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.2.0" + +[[CoordinateTransformations]] +deps = ["Compat", "Rotations", "StaticArrays"] +git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24" +uuid = "150eb455-5306-5404-9cee-2592286d6298" +version = "0.5.0" + +[[CuArrays]] +deps = ["AbstractFFTs", "Adapt", "CUDAapi", "CUDAdrv", "CUDAnative", "DiffRules", "ForwardDiff", "GPUArrays", "LinearAlgebra", "MacroTools", "NNlib", "Pkg", "Printf", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "c1cd8792ca783987fcba2ed0d6b3b58176e6b13e" +uuid = "3a865a2d-5b23-5a0f-bc46-62713ec82fae" +version = "0.9.1" + +[[CustomUnitRanges]] +deps = ["Test"] +git-tree-sha1 = "0a106457a1831555857e18ac9617279c22fc393b" +uuid = "dc8bdbbb-1ca9-579f-8c36-e416f6a65cce" +version = "0.2.0" + +[[DataStructures]] +deps = ["InteractiveUtils", "OrderedCollections", "Random", "Serialization", "Test"] +git-tree-sha1 = "ca971f03e146cf144a9e2f2ce59674f5bf0e8038" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.15.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[DiffResults]] +deps = ["Compat", "StaticArrays"] +git-tree-sha1 = "db8acf46717b13d6c48deb7a12007c7f85a70cf7" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "0.0.3" + +[[DiffRules]] +deps = ["Random", "Test"] +git-tree-sha1 = "09d69da75967ec48a8b1ad0897ec9144ee052bf9" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "0.0.8" + +[[Distances]] +deps = ["LinearAlgebra", "Printf", "Random", "Statistics", "Test"] +git-tree-sha1 = "0e37d8a95bafbeb9c800ef27ab6f443d29e17610" +uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" +version = "0.7.4" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Distributions]] +deps = ["Distributed", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"] +git-tree-sha1 = "c24e9b6500c037673f0241a2783472b8c3d080c7" +uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" +version = "0.16.4" + +[[FFTViews]] +deps = ["CustomUnitRanges", "FFTW", "Test"] +git-tree-sha1 = "9d7993227ca7c0fdb6b31deef193adbba11c8f4e" +uuid = "4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd" +version = "0.2.0" + +[[FFTW]] +deps = ["AbstractFFTs", "BinaryProvider", "Compat", "Conda", "Libdl", "LinearAlgebra", "Reexport", "Test"] +git-tree-sha1 = "29cda58afbf62f35b1a094882ad6c745a47b2eaa" +uuid = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +version = "0.2.4" + +[[FileIO]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "c94b0787956629036fb2b20fccde9e52b89d079a" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.0.5" + +[[FillArrays]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "471b7e33dc9c9c5b9170045dd57c8ba0927b2918" +uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" +version = "0.4.0" + +[[FixedPointNumbers]] +deps = ["Test"] +git-tree-sha1 = "b8045033701c3b10bf2324d7203404be7aef88ba" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.5.3" + +[[Flux]] +deps = ["AbstractTrees", "Adapt", "CodecZlib", "Colors", "DiffRules", "ForwardDiff", "Juno", "LinearAlgebra", "MacroTools", "NNlib", "NaNMath", "Pkg", "Printf", "Random", "Reexport", "Requires", "SHA", "SpecialFunctions", "Statistics", "StatsBase", "Test", "ZipFile"] +git-tree-sha1 = "28e6dbf663fed71ea607414bc5f2f099d2831c0c" +uuid = "587475ba-b771-5e3f-ad9e-33799f191a9c" +version = "0.7.3" + +[[ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"] +git-tree-sha1 = "e393bd3b9102659fb24fe88caedec41f2bc2e7de" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.2" + +[[GPUArrays]] +deps = ["Adapt", "FFTW", "FillArrays", "LinearAlgebra", "Printf", "Random", "Serialization", "StaticArrays", "Test"] +git-tree-sha1 = "2b96d7f25fbea82c08a736d78cbf14df8d2100a5" +uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" +version = "0.6.1" + +[[Graphics]] +deps = ["Colors", "Compat", "NaNMath"] +git-tree-sha1 = "e3ead4211073d4117a0d2ef7d1efc5c8092c8412" +uuid = "a2bd30eb-e257-5431-a919-1863eab51364" +version = "0.4.0" + +[[IdentityRanges]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "b8c36c6083fd14e2a82c5974225702126e894f23" +uuid = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca" +version = "0.3.0" + +[[ImageAxes]] +deps = ["AxisArrays", "Colors", "FixedPointNumbers", "ImageCore", "MappedArrays", "Reexport", "SimpleTraits", "Test"] +git-tree-sha1 = "5735ec90843acaa67a4624611921c686cdf4efbf" +uuid = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac" +version = "0.5.0" + +[[ImageCore]] +deps = ["ColorTypes", "Colors", "FFTW", "FixedPointNumbers", "Graphics", "MappedArrays", "OffsetArrays", "PaddedViews", "Random", "Statistics", "Test"] +git-tree-sha1 = "bd41f7febe7b4d7914c08c5b6d0a69dcd627e3b9" +uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534" +version = "0.7.4" + +[[ImageDistances]] +deps = ["Colors", "Distances", "LinearAlgebra", "ProgressMeter", "Test"] +git-tree-sha1 = "a5de7b61f6fa98fb93c39857fa43cf40ca383b28" +uuid = "51556ac3-7006-55f5-8cb3-34580c88182d" +version = "0.1.1" + +[[ImageFiltering]] +deps = ["CatIndices", "ColorVectorSpace", "Colors", "ComputationalResources", "DataStructures", "FFTViews", "FFTW", "FixedPointNumbers", "ImageCore", "LinearAlgebra", "Logging", "MappedArrays", "OffsetArrays", "Random", "Requires", "StaticArrays", "Statistics", "Test", "TiledIteration"] +git-tree-sha1 = "964ceed5de3c0a7e352cf0e4df2f2a8e628ae00c" +uuid = "6a3955dd-da59-5b1f-98d4-e7296123deb5" +version = "0.5.3" + +[[ImageMagick]] +deps = ["BinaryProvider", "ColorTypes", "FileIO", "FixedPointNumbers", "ImageCore", "InteractiveUtils", "Libdl", "Pkg", "Random", "Test"] +git-tree-sha1 = "0e4cc77fb131061b3525a97fd7d483b253c3aaad" +uuid = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +version = "0.7.1" + +[[ImageMetadata]] +deps = ["AxisArrays", "ColorVectorSpace", "Colors", "Dates", "FixedPointNumbers", "ImageAxes", "ImageCore", "IndirectArrays", "Statistics", "Test"] +git-tree-sha1 = "b389b1eb7145ddd37ebd25f42a387213dc1a18f8" +uuid = "bc367c6b-8a6b-528e-b4bd-a4b897500b49" +version = "0.6.1" + +[[ImageMorphology]] +deps = ["ImageCore", "Test"] +git-tree-sha1 = "e94f43b9ff76f3a3810bfdd9b3d2fbcacbc26fd0" +uuid = "787d08f9-d448-5407-9aad-5290dd7ab264" +version = "0.1.1" + +[[ImageShow]] +deps = ["Base64", "ColorTypes", "Colors", "FileIO", "FixedPointNumbers", "ImageCore", "OffsetArrays", "Requires", "Test"] +git-tree-sha1 = "98eb96a852fd2d6f0905cbe4d215ec2113805b46" +uuid = "4e3cecfd-b093-5904-9786-8bbb286a6a31" +version = "0.1.2" + +[[ImageTransformations]] +deps = ["AxisAlgorithms", "ColorTypes", "ColorVectorSpace", "Colors", "CoordinateTransformations", "FixedPointNumbers", "IdentityRanges", "ImageCore", "Interpolations", "LinearAlgebra", "OffsetArrays", "StaticArrays", "Test"] +git-tree-sha1 = "e32d38356febdd2ab2cca6a3d14b5e5ffcbfb74c" +uuid = "02fcd773-0e25-5acc-982a-7f6622650795" +version = "0.7.2" + +[[Images]] +deps = ["AxisArrays", "Base64", "ColorTypes", "ColorVectorSpace", "Colors", "FileIO", "FixedPointNumbers", "Graphics", "ImageAxes", "ImageCore", "ImageDistances", "ImageFiltering", "ImageMetadata", "ImageMorphology", "ImageShow", "ImageTransformations", "IndirectArrays", "LinearAlgebra", "MappedArrays", "OffsetArrays", "Random", "Reexport", "SIUnits", "SparseArrays", "StaticArrays", "Statistics", "StatsBase", "Test", "TiledIteration"] +git-tree-sha1 = "127aeb2659d97d8f0489ca5cf291cca7fdd3f1f2" +uuid = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +version = "0.17.2" + +[[IndirectArrays]] +deps = ["Compat", "Test"] +git-tree-sha1 = "b6e249be10a3381b2c72ac82f2d13d70067cb2bd" +uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Interpolations]] +deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "Test", "WoodburyMatrices"] +git-tree-sha1 = "e8d1c381b1dc5343e5b6d37265acbe1de493d512" +uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +version = "0.11.2" + +[[IntervalSets]] +deps = ["Compat"] +git-tree-sha1 = "9dc556002f23740de13946e8c2e41798e09a9249" +uuid = "8197267c-284f-5f27-9208-e0e47529a953" +version = "0.3.1" + +[[IterTools]] +deps = ["SparseArrays", "Test"] +git-tree-sha1 = "79246285c43602384e6f1943b3554042a3712056" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.1.1" + +[[JSON]] +deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"] +git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.20.0" + +[[Juno]] +deps = ["Base64", "Logging", "Media", "Profile", "Test"] +git-tree-sha1 = "ce6246e19061e36cbdce954caaae717498daeed8" +uuid = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +version = "0.5.4" + +[[LLVM]] +deps = ["InteractiveUtils", "Libdl", "Printf", "Test", "Unicode"] +git-tree-sha1 = "d98bd8e6e56591caceb7db300a6877fb6daca6ba" +uuid = "929cbde3-209d-540e-8aea-75f648917ca0" +version = "1.0.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Compat"] +git-tree-sha1 = "c443e1c8d58a4e9f61b708ad0a88286c7042145b" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.4.4" + +[[MappedArrays]] +deps = ["Test"] +git-tree-sha1 = "923441c5ac942b60bd3a842d5377d96646bcbf46" +uuid = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" +version = "0.2.1" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Media]] +deps = ["MacroTools", "Test"] +git-tree-sha1 = "75a54abd10709c01f1b86b84ec225d26e840ed58" +uuid = "e89f7d12-3494-54d1-8411-f7d8b9ae1f27" +version = "0.5.0" + +[[Missings]] +deps = ["Dates", "InteractiveUtils", "SparseArrays", "Test"] +git-tree-sha1 = "d1d2585677f2bd93a97cfeb8faa7a0de0f982042" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "0.4.0" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NNlib]] +deps = ["Libdl", "LinearAlgebra", "MacroTools", "Requires", "Test"] +git-tree-sha1 = "51330bb45927379007e089997bf548fbe232589d" +uuid = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +version = "0.4.3" + +[[NaNMath]] +deps = ["Compat"] +git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.2" + +[[OffsetArrays]] +deps = ["DelimitedFiles", "Test"] +git-tree-sha1 = "e6893807f09c1d5517861ded8b203cb96cb7d44a" +uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +version = "0.10.0" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "85619a3f3e17bb4761fe1b1fd47f0e979f964d5b" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.0.2" + +[[PDMats]] +deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] +git-tree-sha1 = "b6c91fc0ab970c0563cbbe69af18d741a49ce551" +uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" +version = "0.9.6" + +[[PaddedViews]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "7da3e7e1a58cffbf10177553ae95f17b92516912" +uuid = "5432bcbf-9aad-5242-b902-cca2824c8663" +version = "0.4.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[ProgressMeter]] +deps = ["Distributed", "Printf", "Random", "Test"] +git-tree-sha1 = "48058bc11607676e5bbc0b974af79106c6200787" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "0.9.0" + +[[QuadGK]] +deps = ["DataStructures", "LinearAlgebra", "Test"] +git-tree-sha1 = "3ce467a8e76c6030d4c3786e7d3a73442017cdc0" +uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +version = "2.0.3" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RangeArrays]] +deps = ["Compat"] +git-tree-sha1 = "d925adfd5b01cb46fde89dc9548d167b3b136f4a" +uuid = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d" +version = "0.3.1" + +[[Ratios]] +deps = ["Compat"] +git-tree-sha1 = "fd159bead0a24e6270fd0573a340312bd4645cc2" +uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" +version = "0.3.0" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["Test"] +git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "0.5.2" + +[[Rmath]] +deps = ["BinaryProvider", "Libdl", "Random", "Statistics", "Test"] +git-tree-sha1 = "9a6c758cdf73036c3239b0afbea790def1dabff9" +uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" +version = "0.5.0" + +[[Rotations]] +deps = ["LinearAlgebra", "Random", "StaticArrays", "Statistics", "Test"] +git-tree-sha1 = "ef8fc0cb5933cb3e2432c6549d7e5c4fd0de353f" +uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc" +version = "0.11.0" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[SIUnits]] +deps = ["Compat", "TexExtensions"] +git-tree-sha1 = "224d83b62711fe7e429454aace2c97eb2cf36031" +uuid = "b9d75638-96e3-5676-bdf0-e9c958f63a55" +version = "0.1.0" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[SimpleTraits]] +deps = ["InteractiveUtils", "MacroTools", "Test"] +git-tree-sha1 = "c0a542b8d5e369b179ccd296b2ca987f6da5da0a" +uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d" +version = "0.8.0" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures", "Random", "Test"] +git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "0.3.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[SpecialFunctions]] +deps = ["BinDeps", "BinaryProvider", "Libdl", "Test"] +git-tree-sha1 = "0b45dc2e45ed77f445617b99ff2adf0f5b0f23ea" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "0.7.2" + +[[StaticArrays]] +deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"] +git-tree-sha1 = "1eb114d6e23a817cd3e99abc3226190876d7c898" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "0.10.2" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsBase]] +deps = ["DataStructures", "DelimitedFiles", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "Test"] +git-tree-sha1 = "7b596062316c7d846b67bf625d5963a832528598" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.27.0" + +[[StatsFuns]] +deps = ["Rmath", "SpecialFunctions", "Test"] +git-tree-sha1 = "b3a4e86aa13c732b8a8c0ba0c3d3264f55e6bb3e" +uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" +version = "0.8.0" + +[[SuiteSparse]] +deps = ["Libdl", "LinearAlgebra", "SparseArrays"] +uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[TexExtensions]] +deps = ["Compat"] +git-tree-sha1 = "092ad55ed044aa5ab31ee800d4ae5bec526a8f09" +uuid = "9b435220-3ad3-5d4f-b1ea-1e7b29ae9b13" +version = "0.1.0" + +[[TiledIteration]] +deps = ["OffsetArrays", "Test"] +git-tree-sha1 = "58f6f07d3b54a363ec283a8f5fc9fb4ecebde656" +uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" +version = "0.2.3" + +[[TranscodingStreams]] +deps = ["Pkg", "Random", "Test"] +git-tree-sha1 = "a34a2d588e2d2825602bf14a24216d5c8b0921ec" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.8.1" + +[[URIParser]] +deps = ["Test", "Unicode"] +git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" +uuid = "30578b45-9adc-5946-b283-645ec420af67" +version = "0.4.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +deps = ["Compat"] +git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.1.3" + +[[WoodburyMatrices]] +deps = ["LinearAlgebra", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "21772c33b447757ec7d3e61fcdfb9ea5c47eedcf" +uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6" +version = "0.4.1" + +[[ZipFile]] +deps = ["BinaryProvider", "Libdl", "Printf", "Test"] +git-tree-sha1 = "4000c633efe994b2e10b31b6d91382c4b7412dac" +uuid = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea" +version = "0.8.0" diff --git a/vision/cuda/Project.toml b/vision/cuda/Project.toml new file mode 100644 index 000000000..bb4fdf153 --- /dev/null +++ b/vision/cuda/Project.toml @@ -0,0 +1,9 @@ +[deps] +BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" +CuArrays = "3a865a2d-5b23-5a0f-bc46-62713ec82fae" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" +Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/vision/mnist/conv.jl b/vision/mnist/conv.jl deleted file mode 100644 index 1e92d9b78..000000000 --- a/vision/mnist/conv.jl +++ /dev/null @@ -1,126 +0,0 @@ -# Classifies MNIST digits with a convolutional network. -# Writes out saved model to the file "mnist_conv.bson". -# Demonstrates basic model construction, training, saving, -# conditional early-exit, and learning rate scheduling. -# -# This model, while simple, should hit around 99% test -# accuracy after training for approximately 20 epochs. - -using Flux, Flux.Data.MNIST, Statistics -using Flux: onehotbatch, onecold, crossentropy, throttle -using Base.Iterators: repeated, partition -using Printf, BSON - -# Load labels and images from Flux.Data.MNIST -@info("Loading data set") -train_labels = MNIST.labels() -train_imgs = MNIST.images() - -# Bundle images together with labels and group into minibatchess -function make_minibatch(X, Y, idxs) - X_batch = Array{Float32}(undef, size(X[1])..., 1, length(idxs)) - for i in 1:length(idxs) - X_batch[:, :, :, i] = Float32.(X[idxs[i]]) - end - Y_batch = onehotbatch(Y[idxs], 0:9) - return (X_batch, Y_batch) -end -batch_size = 128 -mb_idxs = partition(1:length(train_imgs), batch_size) -train_set = [make_minibatch(train_imgs, train_labels, i) for i in mb_idxs] - -# Prepare test set as one giant minibatch: -test_imgs = MNIST.images(:test) -test_labels = MNIST.labels(:test) -test_set = make_minibatch(test_imgs, test_labels, 1:length(test_imgs)) - -# Define our model. We will use a simple convolutional architecture with -# three iterations of Conv -> ReLU -> MaxPool, followed by a final Dense -# layer that feeds into a softmax probability output. -@info("Constructing model...") -model = Chain( - # First convolution, operating upon a 28x28 image - Conv((3, 3), 1=>16, pad=(1,1), relu), - x -> maxpool(x, (2,2)), - - # Second convolution, operating upon a 14x14 image - Conv((3, 3), 16=>32, pad=(1,1), relu), - x -> maxpool(x, (2,2)), - - # Third convolution, operating upon a 7x7 image - Conv((3, 3), 32=>32, pad=(1,1), relu), - x -> maxpool(x, (2,2)), - - # Reshape 3d tensor into a 2d one, at this point it should be (3, 3, 32, N) - # which is where we get the 288 in the `Dense` layer below: - x -> reshape(x, :, size(x, 4)), - Dense(288, 10), - - # Finally, softmax to get nice probabilities - softmax, -) - -# Load model and datasets onto GPU, if enabled -train_set = gpu.(train_set) -test_set = gpu.(test_set) -model = gpu(model) - -# Make sure our model is nicely precompiled before starting our training loop -model(train_set[1][1]) - -# `loss()` calculates the crossentropy loss between our prediction `y_hat` -# (calculated from `model(x)`) and the ground truth `y`. We augment the data -# a bit, adding gaussian random noise to our image to make it more robust. -function loss(x, y) - # We augment `x` a little bit here, adding in random noise - x_aug = x .+ 0.1f0*gpu(randn(eltype(x), size(x))) - - y_hat = model(x_aug) - return crossentropy(y_hat, y) -end -accuracy(x, y) = mean(onecold(model(x)) .== onecold(y)) - -# Train our model with the given training set using the ADAM optimizer and -# printing out performance against the test set as we go. -opt = ADAM(0.001) - -@info("Beginning training loop...") -best_acc = 0.0 -last_improvement = 0 -for epoch_idx in 1:100 - global best_acc, last_improvement - # Train for a single epoch - Flux.train!(loss, params(model), train_set, opt) - - # Calculate accuracy: - acc = accuracy(test_set...) - @info(@sprintf("[%d]: Test accuracy: %.4f", epoch_idx, acc)) - - # If our accuracy is good enough, quit out. - if acc >= 0.999 - @info(" -> Early-exiting: We reached our target accuracy of 99.9%") - break - end - - # If this is the best accuracy we've seen so far, save the model out - if acc >= best_acc - @info(" -> New best accuracy! Saving model out to mnist_conv.bson") - BSON.@save "mnist_conv.bson" model epoch_idx acc - best_acc = acc - last_improvement = epoch_idx - end - - # If we haven't seen improvement in 5 epochs, drop our learning rate: - if epoch_idx - last_improvement >= 5 && opt.eta > 1e-6 - opt.eta /= 10.0 - @warn(" -> Haven't improved in a while, dropping learning rate to $(opt.eta)!") - - # After dropping learning rate, give it a few epochs to improve - last_improvement = epoch_idx - end - - if epoch_idx - last_improvement >= 10 - @warn(" -> We're calling this converged.") - break - end -end diff --git a/vision/mnist/vae.jl b/vision/mnist/vae.jl deleted file mode 100644 index 66c821dd4..000000000 --- a/vision/mnist/vae.jl +++ /dev/null @@ -1,67 +0,0 @@ -using Flux, Flux.Data.MNIST, Statistics -using Flux: throttle, params -using Juno: @progress - -# Extend distributions slightly to have a numerically stable logpdf for `p` close to 1 or 0. -using Distributions -import Distributions: logpdf -logpdf(b::Bernoulli, y::Bool) = y * log(b.p + eps(Float32)) + (1f0 - y) * log(1 - b.p + eps(Float32)) - -# Load data, binarise it, and partition into mini-batches of M. -X = float.(hcat(vec.(MNIST.images())...)) .> 0.5 -N, M = size(X, 2), 100 -data = [X[:,i] for i in Iterators.partition(1:N,M)] - - -################################# Define Model ################################# - -# Latent dimensionality, # hidden units. -Dz, Dh = 5, 500 - -# Components of recognition model / "encoder" MLP. -A, μ, logσ = Dense(28^2, Dh, tanh), Dense(Dh, Dz), Dense(Dh, Dz) -g(X) = (h = A(X); (μ(h), logσ(h))) -z(μ, logσ) = μ + exp(logσ) * randn(Float32) - -# Generative model / "decoder" MLP. -f = Chain(Dense(Dz, Dh, tanh), Dense(Dh, 28^2, σ)) - - -####################### Define ways of doing things with the model. ####################### - -# KL-divergence between approximation posterior and N(0, 1) prior. -kl_q_p(μ, logσ) = 0.5f0 * sum(exp.(2f0 .* logσ) + μ.^2 .- 1f0 .+ logσ.^2) - -# logp(x|z) - conditional probability of data given latents. -logp_x_z(x, z) = sum(logpdf.(Bernoulli.(f(z)), x)) - -# Monte Carlo estimator of mean ELBO using M samples. -L̄(X) = ((μ̂, logσ̂) = g(X); (logp_x_z(X, z.(μ̂, logσ̂)) - kl_q_p(μ̂, logσ̂)) * 1 // M) - -loss(X) = -L̄(X) + 0.01f0 * sum(x->sum(x.^2), params(f)) - -# Sample from the learned model. -modelsample() = rand.(Bernoulli.(f(z.(zeros(Dz), zeros(Dz))))) - - -################################# Learn Parameters ############################## - -evalcb = throttle(() -> @show(-L̄(X[:, rand(1:N, M)])), 30) -opt = ADAM() -ps = params(A, μ, logσ, f) - -@progress for i = 1:20 - @info "Epoch $i" - Flux.train!(loss, ps, zip(data), opt, cb=evalcb) -end - - -################################# Sample Output ############################## - -using Images - -img(x) = Gray.(reshape(x, 28, 28)) - -cd(@__DIR__) -sample = hcat(img.([modelsample() for i = 1:10])...) -save("sample.png", sample)