From 5fc22e527f80980529fd27ee70be70a7ee70e6ee Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Tue, 11 Aug 2020 17:19:51 +0400 Subject: [PATCH 1/7] added VGG models as a first part of restructuring --- .../.ipynb_checkpoints/VGG16-checkpoint.ipynb | 439 ++++++++++++++++++ .../.ipynb_checkpoints/VGG19-checkpoint.ipynb | 438 +++++++++++++++++ vision/{cifar10 => VGG}/Manifest.toml | 0 vision/{cifar10 => VGG}/Project.toml | 0 vision/VGG/README.md | 9 + vision/VGG/README.md~ | 3 + vision/VGG/VGG16.ipynb | 439 ++++++++++++++++++ vision/VGG/VGG16.jl | 76 +++ vision/VGG/VGG19.ipynb | 438 +++++++++++++++++ vision/VGG/VGG19.jl | 75 +++ vision/cifar10/cifar10.jl | 136 ------ 11 files changed, 1917 insertions(+), 136 deletions(-) create mode 100644 vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb create mode 100644 vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb rename vision/{cifar10 => VGG}/Manifest.toml (100%) rename vision/{cifar10 => VGG}/Project.toml (100%) create mode 100644 vision/VGG/README.md create mode 100644 vision/VGG/README.md~ create mode 100644 vision/VGG/VGG16.ipynb create mode 100644 vision/VGG/VGG16.jl create mode 100644 vision/VGG/VGG19.ipynb create mode 100644 vision/VGG/VGG19.jl delete mode 100644 vision/cifar10/cifar10.jl diff --git a/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb b/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb new file mode 100644 index 000000000..65f8ab4ee --- /dev/null +++ b/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb @@ -0,0 +1,439 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:29:16.357000+04:00", + "start_time": "2020-08-11T12:28:53.552Z" + } + }, + "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": 126, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:55:19.835000+04:00", + "start_time": "2020-08-11T12:55:18.394Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "┌ Info: Precompiling Flatten [4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa]\n", + "└ @ Base loading.jl:1278\n", + "WARNING: using Flatten.flatten in module Main conflicts with an existing identifier.\n" + ] + } + ], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:55:11.078000+04:00", + "start_time": "2020-08-11T12:55:11.076Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "getarray (generic function with 1 method)" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:07:39.471000+04:00", + "start_time": "2020-08-11T13:07:35.047Z" + }, + "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": 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": 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() = 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", + " 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", + " 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", + " 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": 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..e39e6811d --- /dev/null +++ b/vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb @@ -0,0 +1,438 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.147000+04:00", + "start_time": "2020-08-11T13:13:16.198Z" + } + }, + "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": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.377000+04:00", + "start_time": "2020-08-11T13:13:16.405Z" + } + }, + "outputs": [], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.861000+04:00", + "start_time": "2020-08-11T13:13:16.558Z" + } + }, + "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": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:45.622000+04:00", + "start_time": "2020-08-11T13:13:16.700Z" + }, + "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": 5, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:46.662000+04:00", + "start_time": "2020-08-11T13:13:16.900Z" + } + }, + "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": 5, + "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": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:46.743000+04:00", + "start_time": "2020-08-11T13:13:17.068Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "vgg19 (generic function with 1 method)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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/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/cifar10/Project.toml b/vision/VGG/Project.toml similarity index 100% rename from vision/cifar10/Project.toml rename to vision/VGG/Project.toml 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..65f8ab4ee --- /dev/null +++ b/vision/VGG/VGG16.ipynb @@ -0,0 +1,439 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

Table of Contents

\n", + "
    " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:29:16.357000+04:00", + "start_time": "2020-08-11T12:28:53.552Z" + } + }, + "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": 126, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:55:19.835000+04:00", + "start_time": "2020-08-11T12:55:18.394Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "┌ Info: Precompiling Flatten [4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa]\n", + "└ @ Base loading.jl:1278\n", + "WARNING: using Flatten.flatten in module Main conflicts with an existing identifier.\n" + ] + } + ], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T16:55:11.078000+04:00", + "start_time": "2020-08-11T12:55:11.076Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "getarray (generic function with 1 method)" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" + ] + }, + { + "cell_type": "code", + "execution_count": 184, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:07:39.471000+04:00", + "start_time": "2020-08-11T13:07:35.047Z" + }, + "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": 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": 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() = 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", + " 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", + " 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", + " 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": 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/VGG16.jl b/vision/VGG/VGG16.jl new file mode 100644 index 000000000..07a98449f --- /dev/null +++ b/vision/VGG/VGG16.jl @@ -0,0 +1,76 @@ +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))) + +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 + +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), + MaxPool((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), + MaxPool((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), + MaxPool((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), + MaxPool((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), + MaxPool((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 + +m = vgg16() + +conv_block(in_channels, out_channels) = return Chain( + Conv((3,3), in_channels => out_channels, relu, pad = (1,1), stride = (1,1)), + BatchNorm(out_channels)) + +loss(x, y) = crossentropy(m(x), y) + +Chain(double_conv(2, 3)) + +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..e39e6811d --- /dev/null +++ b/vision/VGG/VGG19.ipynb @@ -0,0 +1,438 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "toc": true + }, + "source": [ + "

    Table of Contents

    \n", + "
      " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.147000+04:00", + "start_time": "2020-08-11T13:13:16.198Z" + } + }, + "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": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.377000+04:00", + "start_time": "2020-08-11T13:13:16.405Z" + } + }, + "outputs": [], + "source": [ + "using Flatten" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:39.861000+04:00", + "start_time": "2020-08-11T13:13:16.558Z" + } + }, + "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": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:45.622000+04:00", + "start_time": "2020-08-11T13:13:16.700Z" + }, + "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": 5, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:46.662000+04:00", + "start_time": "2020-08-11T13:13:16.900Z" + } + }, + "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": 5, + "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": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2020-08-11T17:13:46.743000+04:00", + "start_time": "2020-08-11T13:13:17.068Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "vgg19 (generic function with 1 method)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "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/VGG19.jl b/vision/VGG/VGG19.jl new file mode 100644 index 000000000..34d004502 --- /dev/null +++ b/vision/VGG/VGG19.jl @@ -0,0 +1,75 @@ +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))) + +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 + +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), + MaxPool((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), + MaxPool((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)), + MaxPool((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)), + MaxPool((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)), + MaxPool((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 + +m = vgg19() + +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/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)) From 1d0cf40e3ac278313873be85efc0a53dc9f51b27 Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Tue, 11 Aug 2020 17:23:33 +0400 Subject: [PATCH 2/7] added VGG models as a first part of restructuring --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9a477bff9..2a87551a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ notebooks +*.checkpoints From 5a6321ea5080f0267ceb3fc237370c4c666f128b Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Tue, 11 Aug 2020 17:23:52 +0400 Subject: [PATCH 3/7] added VGG models as a first part of restructuring --- .../.ipynb_checkpoints/VGG16-checkpoint.ipynb | 439 ------------------ .../.ipynb_checkpoints/VGG19-checkpoint.ipynb | 438 ----------------- 2 files changed, 877 deletions(-) delete mode 100644 vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb delete mode 100644 vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb diff --git a/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb b/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb deleted file mode 100644 index 65f8ab4ee..000000000 --- a/vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb +++ /dev/null @@ -1,439 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "toc": true - }, - "source": [ - "

      Table of Contents

      \n", - "
        " - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T16:29:16.357000+04:00", - "start_time": "2020-08-11T12:28:53.552Z" - } - }, - "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": 126, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T16:55:19.835000+04:00", - "start_time": "2020-08-11T12:55:18.394Z" - } - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "┌ Info: Precompiling Flatten [4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa]\n", - "└ @ Base loading.jl:1278\n", - "WARNING: using Flatten.flatten in module Main conflicts with an existing identifier.\n" - ] - } - ], - "source": [ - "using Flatten" - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T16:55:11.078000+04:00", - "start_time": "2020-08-11T12:55:11.076Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "getarray (generic function with 1 method)" - ] - }, - "execution_count": 122, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" - ] - }, - { - "cell_type": "code", - "execution_count": 184, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:07:39.471000+04:00", - "start_time": "2020-08-11T13:07:35.047Z" - }, - "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": 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": 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() = 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", - " 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", - " 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", - " 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": 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 deleted file mode 100644 index e39e6811d..000000000 --- a/vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb +++ /dev/null @@ -1,438 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "toc": true - }, - "source": [ - "

        Table of Contents

        \n", - "
          " - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.147000+04:00", - "start_time": "2020-08-11T13:13:16.198Z" - } - }, - "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": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.377000+04:00", - "start_time": "2020-08-11T13:13:16.405Z" - } - }, - "outputs": [], - "source": [ - "using Flatten" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.861000+04:00", - "start_time": "2020-08-11T13:13:16.558Z" - } - }, - "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": 4, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:45.622000+04:00", - "start_time": "2020-08-11T13:13:16.700Z" - }, - "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": 5, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:46.662000+04:00", - "start_time": "2020-08-11T13:13:16.900Z" - } - }, - "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": 5, - "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": 6, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T17:13:46.743000+04:00", - "start_time": "2020-08-11T13:13:17.068Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "vgg19 (generic function with 1 method)" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "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 -} From c87e9eda4d4a403ef40876f7d4860b660d047551 Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Tue, 11 Aug 2020 23:09:51 +0400 Subject: [PATCH 4/7] refactor VGG and make a template for future use --- .../.ipynb_checkpoints/VGG16-checkpoint.ipynb | 552 ++++++++++++++++++ .../.ipynb_checkpoints/VGG19-checkpoint.ipynb | 429 ++++++++++++++ vision/VGG/Project.toml | 1 - vision/VGG/VGG16.ipynb | 353 ++++++----- vision/VGG/VGG16.jl | 119 ++-- vision/VGG/VGG19.ipynb | 254 ++++---- vision/VGG/VGG19.jl | 127 ++-- 7 files changed, 1457 insertions(+), 378 deletions(-) create mode 100644 vision/VGG/.ipynb_checkpoints/VGG16-checkpoint.ipynb create mode 100644 vision/VGG/.ipynb_checkpoints/VGG19-checkpoint.ipynb 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/Project.toml b/vision/VGG/Project.toml index 9c279df9e..403c36342 100644 --- a/vision/VGG/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/VGG16.ipynb b/vision/VGG/VGG16.ipynb index 65f8ab4ee..e9d56b1f9 100644 --- a/vision/VGG/VGG16.ipynb +++ b/vision/VGG/VGG16.ipynb @@ -12,78 +12,67 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T16:29:16.357000+04:00", - "start_time": "2020-08-11T12:28:53.552Z" - } - }, - "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": 126, - "metadata": { - "ExecuteTime": { - "end_time": "2020-08-11T16:55:19.835000+04:00", - "start_time": "2020-08-11T12:55:18.394Z" - } + "end_time": "2020-08-11T22:10:02.179000+04:00", + "start_time": "2020-08-11T18:09:21.430Z" + }, + "scrolled": true, + "tags": [] }, "outputs": [ { - "name": "stderr", "output_type": "stream", - "text": [ - "┌ Info: Precompiling Flatten [4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa]\n", - "└ @ Base loading.jl:1278\n", - "WARNING: using Flatten.flatten in module Main conflicts with an existing identifier.\n" - ] + "name": "stderr", + "text": "┌ Info: Precompiling Metalhead [dbeba491-748d-5e0e-a39e-b530a07fa0cc]\n└ @ Base loading.jl:1278\n" } ], "source": [ - "using Flatten" + "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": 122, + "execution_count": 8, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T16:55:11.078000+04:00", - "start_time": "2020-08-11T12:55:11.076Z" + "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)" - ] + "text/plain": "getarray (generic function with 1 method)" }, - "execution_count": 122, "metadata": {}, - "output_type": "execute_result" + "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": 184, + "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:07:39.471000+04:00", - "start_time": "2020-08-11T13:07:35.047Z" + "end_time": "2020-08-11T21:47:47.459000+04:00", + "start_time": "2020-08-11T17:47:47.448Z" }, "scrolled": true }, @@ -97,33 +86,27 @@ }, { "cell_type": "code", - "execution_count": 4, + "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{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" - ] + "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" }, - "execution_count": 4, "metadata": {}, - "output_type": "execute_result" + "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": [ @@ -132,9 +115,90 @@ "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": 173, + "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", @@ -143,61 +207,37 @@ }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "vgg16 (generic function with 2 methods)" - ] + "text/plain": "vgg16 (generic function with 1 method)" }, - "execution_count": 173, "metadata": {}, - "output_type": "execute_result" + "execution_count": 68 } ], "source": [ - "vgg16() = 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", - " 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", - " 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", - " 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" + "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, + "execution_count": 69, "metadata": { "ExecuteTime": { "end_time": "2020-08-11T17:05:08.454000+04:00", @@ -206,23 +246,21 @@ }, "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)), #36, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" - ] + "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)" }, - "execution_count": 174, "metadata": {}, - "output_type": "execute_result" + "execution_count": 69 } ], "source": [ - "m = vgg16()" + "m = vgg16(3, 10)" ] }, { "cell_type": "code", - "execution_count": 178, + "execution_count": 70, "metadata": { "ExecuteTime": { "end_time": "2020-08-11T17:05:11.842000+04:00", @@ -231,14 +269,12 @@ }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "loss (generic function with 1 method)" - ] + "text/plain": "loss (generic function with 1 method)" }, - "execution_count": 178, "metadata": {}, - "output_type": "execute_result" + "execution_count": 70 } ], "source": [ @@ -247,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 180, + "execution_count": 71, "metadata": { "ExecuteTime": { "end_time": "2020-08-11T17:05:12.481000+04:00", @@ -256,14 +292,12 @@ }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "accuracy (generic function with 1 method)" - ] + "text/plain": "accuracy (generic function with 1 method)" }, - "execution_count": 180, "metadata": {}, - "output_type": "execute_result" + "execution_count": 71 } ], "source": [ @@ -272,7 +306,7 @@ }, { "cell_type": "code", - "execution_count": 181, + "execution_count": 72, "metadata": { "ExecuteTime": { "end_time": "2020-08-11T17:05:13.807000+04:00", @@ -281,14 +315,12 @@ }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "(::Flux.var\"#throttled#20\"{Flux.var\"#throttled#16#21\"{Bool,Bool,var\"#39#40\",Int64}}) (generic function with 1 method)" - ] + "text/plain": "(::Flux.var\"#throttled#42\"{Flux.var\"#throttled#38#43\"{Bool,Bool,var\"#43#44\",Int64}}) (generic function with 1 method)" }, - "execution_count": 181, "metadata": {}, - "output_type": "execute_result" + "execution_count": 72 } ], "source": [ @@ -297,7 +329,7 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": 73, "metadata": { "ExecuteTime": { "end_time": "2020-08-11T17:05:14.409000+04:00", @@ -306,14 +338,12 @@ }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" - ] + "text/plain": "ADAM(0.001, (0.9, 0.999), IdDict{Any,Any}())" }, - "execution_count": 182, "metadata": {}, - "output_type": "execute_result" + "execution_count": 73 } ], "source": [ @@ -322,61 +352,24 @@ }, { "cell_type": "code", - "execution_count": 183, + "execution_count": 74, "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" - ] - } - ], + "outputs": [], "source": [ "Flux.train!(loss, params(m), train, opt, cb = evalcb)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -436,4 +429,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/vision/VGG/VGG16.jl b/vision/VGG/VGG16.jl index 07a98449f..1c321f9f0 100644 --- a/vision/VGG/VGG16.jl +++ b/vision/VGG/VGG16.jl @@ -1,76 +1,105 @@ +# 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 -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), - MaxPool((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), - MaxPool((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), - MaxPool((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), - MaxPool((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), - MaxPool((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 - -m = vgg16() - -conv_block(in_channels, out_channels) = return Chain( +# %% [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 + +# %% +collect(Iterators.repeated(conv_block(256, 256),3)) + + +# %% +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) -Chain(double_conv(2, 3)) +# %% 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 index e39e6811d..e6cd24f28 100644 --- a/vision/VGG/VGG19.ipynb +++ b/vision/VGG/VGG19.ipynb @@ -12,14 +12,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.147000+04:00", - "start_time": "2020-08-11T13:13:16.198Z" - } + "start_time": "2020-08-11T15:19:23.051Z" + }, + "tags": [] }, - "outputs": [], + "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", @@ -30,11 +36,10 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.377000+04:00", - "start_time": "2020-08-11T13:13:16.405Z" + "start_time": "2020-08-11T15:19:23.691Z" } }, "outputs": [], @@ -44,36 +49,30 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:13:39.861000+04:00", - "start_time": "2020-08-11T13:13:16.558Z" + "start_time": "2020-08-11T15:19:23.874Z" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "getarray (generic function with 1 method)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "getarray(X) = Float32.(permutedims(channelview(X), (2, 3, 1)))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CIFAR 10 dataset" + ] + }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:13:45.622000+04:00", - "start_time": "2020-08-11T13:13:16.700Z" + "start_time": "2020-08-11T15:19:24.076Z" }, "scrolled": true }, @@ -87,110 +86,151 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2020-08-11T17:13:46.662000+04:00", - "start_time": "2020-08-11T13:13:16.900Z" + "start_time": "2020-08-11T15:19:24.610Z" } }, - "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": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "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": { - "end_time": "2020-08-11T17:13:46.743000+04:00", - "start_time": "2020-08-11T13:13:17.068Z" + "start_time": "2020-08-11T15:19:25.027Z" } }, "outputs": [ { + "output_type": "execute_result", "data": { - "text/plain": [ - "vgg19 (generic function with 1 method)" - ] + "text/plain": "conv_block (generic function with 1 method)" }, - "execution_count": 6, "metadata": {}, - "output_type": "execute_result" + "execution_count": 6 } ], "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" + "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": 15, + "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", @@ -199,18 +239,16 @@ }, "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)), #7, Dense(512, 4096, relu), Dropout(0.5), Dense(4096, 4096, relu), Dropout(0.5), Dense(4096, 10), softmax)" - ] + "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)" }, - "execution_count": 15, "metadata": {}, - "output_type": "execute_result" + "execution_count": 10 } ], "source": [ - "m = vgg19()" + "m = vgg19(3, 10)" ] }, { @@ -435,4 +473,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/vision/VGG/VGG19.jl b/vision/VGG/VGG19.jl index 34d004502..234f911a5 100644 --- a/vision/VGG/VGG19.jl +++ b/vision/VGG/VGG19.jl @@ -1,75 +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 -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), - MaxPool((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), - MaxPool((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)), - MaxPool((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)), - MaxPool((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)), - MaxPool((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 - -m = vgg19() +# %% [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) +# %% + + + From f55483ad274b029ec72b2db96ea46ad7b48a3b94 Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Tue, 11 Aug 2020 23:33:50 +0400 Subject: [PATCH 5/7] refactored CPPN and optimized loops --- .../Manifest.toml | 0 .../Project.toml | 0 vision/compositionalPatternNetwork/README.md | 5 + vision/compositionalPatternNetwork/cppn.ipynb | 285 ++++++++++++++++++ .../cppn.jl | 53 +++- vision/cppn/sample.png | Bin 36791 -> 0 bytes 6 files changed, 329 insertions(+), 14 deletions(-) rename vision/{cppn => compositionalPatternNetwork}/Manifest.toml (100%) rename vision/{cppn => compositionalPatternNetwork}/Project.toml (100%) create mode 100644 vision/compositionalPatternNetwork/README.md create mode 100644 vision/compositionalPatternNetwork/cppn.ipynb rename vision/{cppn => compositionalPatternNetwork}/cppn.jl (60%) delete mode 100644 vision/cppn/sample.png diff --git a/vision/cppn/Manifest.toml b/vision/compositionalPatternNetwork/Manifest.toml similarity index 100% rename from vision/cppn/Manifest.toml rename to vision/compositionalPatternNetwork/Manifest.toml diff --git a/vision/cppn/Project.toml b/vision/compositionalPatternNetwork/Project.toml similarity index 100% rename from vision/cppn/Project.toml rename to vision/compositionalPatternNetwork/Project.toml diff --git a/vision/compositionalPatternNetwork/README.md b/vision/compositionalPatternNetwork/README.md new file mode 100644 index 000000000..00b08a6ba --- /dev/null +++ b/vision/compositionalPatternNetwork/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/compositionalPatternNetwork/cppn.ipynb b/vision/compositionalPatternNetwork/cppn.ipynb new file mode 100644 index 000000000..a6c335c9d --- /dev/null +++ b/vision/compositionalPatternNetwork/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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "using Images\n", + "using Flux" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "262144" + }, + "metadata": {}, + "execution_count": 3 + } + ], + "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": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "cast (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 4 + } + ], + "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": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "unit (generic function with 4 methods)" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "unit(in=N, out=N, f=tanh) = Dense(in, out, f, initW=randn)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "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": 12 + } + ], + "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": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getColorAt (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 13 + } + ], + "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": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "batch (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 15 + } + ], + "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": 16, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "getImage (generic function with 1 method)" + }, + "metadata": {}, + "execution_count": 16 + } + ], + "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": 17, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "saveImg (generic function with 2 methods)" + }, + "metadata": {}, + "execution_count": 17 + } + ], + "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": 21, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "10-element Array{Array{Gray{Float64},2},1}:\n [Gray{Float64}(0.2521996716071073) Gray{Float64}(0.25208851762208667) … Gray{Float64}(0.0015289917006011853) Gray{Float64}(0.0015448003400139547); Gray{Float64}(0.25239783981898306) Gray{Float64}(0.25229741836939806) … Gray{Float64}(0.0015409862430406161) Gray{Float64}(0.0015556662740844232); … ; Gray{Float64}(0.0017829869376063436) Gray{Float64}(0.0026525768972253706) … Gray{Float64}(2.5223646445120956e-5) Gray{Float64}(2.47288565856985e-5); Gray{Float64}(0.0021263943914968273) Gray{Float64}(0.0034270737238509975) … Gray{Float64}(2.5486151197834786e-5) Gray{Float64}(2.4966840185825434e-5)]\n [Gray{Float64}(0.04308058429138164) Gray{Float64}(0.04298489327583355) … Gray{Float64}(0.02395747412844401) Gray{Float64}(0.01825646521918251); Gray{Float64}(0.042357330642080644) Gray{Float64}(0.04226691210935509) … Gray{Float64}(0.026345335774048913) Gray{Float64}(0.020041252132139604); … ; Gray{Float64}(0.003412506038343691) Gray{Float64}(0.002221820144178228) … Gray{Float64}(0.0018362171855862831) Gray{Float64}(0.0018332075817697573); Gray{Float64}(0.002435270554345871) Gray{Float64}(0.001489592740363692) … Gray{Float64}(0.0018386287049532927) Gray{Float64}(0.0018355919756633853)]\n [Gray{Float64}(0.014298084086568122) Gray{Float64}(0.014324288214250564) … Gray{Float64}(0.9911107714992583) Gray{Float64}(0.9911459570024385); Gray{Float64}(0.014186650772934082) Gray{Float64}(0.01420328980281595) … Gray{Float64}(0.9910717171717492) Gray{Float64}(0.9911808390164447); … ; Gray{Float64}(0.007993432967378073) Gray{Float64}(0.007965210499122834) … Gray{Float64}(0.9995315968561617) Gray{Float64}(0.9995757652869915); Gray{Float64}(0.007982785748163017) Gray{Float64}(0.007955710258358556) … Gray{Float64}(0.9996836003825987) Gray{Float64}(0.9997056943263476)]\n [Gray{Float64}(0.015536578113201641) Gray{Float64}(0.014992500787099152) … Gray{Float64}(0.25074936822968935) Gray{Float64}(0.24315139994226095); Gray{Float64}(0.01636157410929065) Gray{Float64}(0.015775227066491745) … Gray{Float64}(0.2477865051090734) Gray{Float64}(0.24043556827024629); … ; Gray{Float64}(0.7550746838221093) Gray{Float64}(0.7707165960236805) … Gray{Float64}(6.237419400537261e-5) Gray{Float64}(6.22342831979618e-5); Gray{Float64}(0.7583733549015652) Gray{Float64}(0.7744211567286908) … Gray{Float64}(6.244808635589365e-5) Gray{Float64}(6.230425840066295e-5)]\n [Gray{Float64}(0.40349708429990105) Gray{Float64}(0.39594331940546873) … Gray{Float64}(0.7112214318795447) Gray{Float64}(0.9266997646159046); Gray{Float64}(0.4058746480975122) Gray{Float64}(0.39841189045429143) … Gray{Float64}(0.7563153862749679) Gray{Float64}(0.9583061863052459); … ; Gray{Float64}(0.2593485036863934) Gray{Float64}(0.24234234961321183) … Gray{Float64}(5.04895929519495e-5) Gray{Float64}(5.055041024670008e-5); Gray{Float64}(0.26511931629309704) Gray{Float64}(0.24818105377582633) … Gray{Float64}(5.04997816038374e-5) Gray{Float64}(5.056025343106645e-5)]\n [Gray{Float64}(0.011988700904424852) Gray{Float64}(0.012381599135965416) … Gray{Float64}(0.21665849661980888) Gray{Float64}(0.21069024138460954); Gray{Float64}(0.011840679190036087) Gray{Float64}(0.012211270644579563) … Gray{Float64}(0.2137690672860282) Gray{Float64}(0.2077362977789327); … ; Gray{Float64}(0.41743798122440623) Gray{Float64}(0.37715856994616664) … Gray{Float64}(5.65624834875122e-5) Gray{Float64}(5.724315774770719e-5); Gray{Float64}(0.4192879001144961) Gray{Float64}(0.37915739484747346) … Gray{Float64}(5.699018761016964e-5) Gray{Float64}(5.7715173969834814e-5)]\n [Gray{Float64}(0.5274539672626967) Gray{Float64}(0.6078297427476608) … Gray{Float64}(0.9971539222363504) Gray{Float64}(0.9971358005395428); Gray{Float64}(0.49660883341051043) Gray{Float64}(0.5858615612968465) … Gray{Float64}(0.9971146043013612) Gray{Float64}(0.9971498841802217); … ; Gray{Float64}(0.334778955711171) Gray{Float64}(0.3626231735964442) … Gray{Float64}(5.103743748029504e-5) Gray{Float64}(5.106829160945218e-5); Gray{Float64}(0.34176599876498104) Gray{Float64}(0.36960942276096265) … Gray{Float64}(5.109449768526464e-5) Gray{Float64}(5.112493782639378e-5)]\n [Gray{Float64}(0.09942807535185516) Gray{Float64}(0.10269334284759067) … Gray{Float64}(4.4263681912655106e-5) Gray{Float64}(4.396736472205468e-5); Gray{Float64}(0.09946479082476775) Gray{Float64}(0.10271394900518027) … Gray{Float64}(4.402928393718721e-5) Gray{Float64}(4.3745394598599085e-5); … ; Gray{Float64}(0.9999096607353399) Gray{Float64}(0.9999048956799765) … Gray{Float64}(0.0007687601399143501) Gray{Float64}(0.0006986173881198039); Gray{Float64}(0.9999075276834276) Gray{Float64}(0.9999027976719367) … Gray{Float64}(0.0007843822193858346) Gray{Float64}(0.0007081345928318678)]\n [Gray{Float64}(0.3128185787267912) Gray{Float64}(0.31925348550338706) … Gray{Float64}(0.0017067946350244642) Gray{Float64}(0.0017092982686498363); Gray{Float64}(0.3112719474509596) Gray{Float64}(0.3179476059393161) … Gray{Float64}(0.0017101118545847164) Gray{Float64}(0.0017126693049325222); … ; Gray{Float64}(0.10206570081006515) Gray{Float64}(0.1369357348134079) … Gray{Float64}(3.0108501936791908e-5) Gray{Float64}(2.9429901574261386e-5); Gray{Float64}(0.11611197005304527) Gray{Float64}(0.15208073341651163) … Gray{Float64}(3.0386762741253214e-5) Gray{Float64}(2.9706981745823352e-5)]\n [Gray{Float64}(0.9139554840092061) Gray{Float64}(0.9268222540667976) … Gray{Float64}(0.6739474146712492) Gray{Float64}(0.6727704844839109); Gray{Float64}(0.9158487702719089) Gray{Float64}(0.9231819529375643) … Gray{Float64}(0.672909516787164) Gray{Float64}(0.671720138604213); … ; Gray{Float64}(0.0006547176463694403) Gray{Float64}(0.0006339610402856328) … Gray{Float64}(7.760013279088737e-5) Gray{Float64}(7.733330843616922e-5); Gray{Float64}(0.0006209573405352554) Gray{Float64}(0.000607837698818018) … Gray{Float64}(7.799381741515829e-5) Gray{Float64}(7.773003638801709e-5)]", + "text/html": "
                  (a vector displayed as a row to save space)
                  " + }, + "metadata": {}, + "execution_count": 21 + } + ], + "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/compositionalPatternNetwork/cppn.jl similarity index 60% rename from vision/cppn/cppn.jl rename to vision/compositionalPatternNetwork/cppn.jl index 0e2e7f237..68528a150 100644 --- a/vision/cppn/cppn.jl +++ b/vision/compositionalPatternNetwork/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/cppn/sample.png b/vision/cppn/sample.png deleted file mode 100644 index 6b7726f25e3061c49ad245b4a4edc2b6a075f23a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 36791 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 From 847e71260c9764e13d17692333590377c466c0e4 Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Wed, 12 Aug 2020 12:12:12 +0400 Subject: [PATCH 6/7] refactored VAE --- vision/VAE/Manifest.toml | 582 ++++++++++++++++++ vision/VAE/Project.toml | 8 + vision/VAE/README.md | 4 + vision/VAE/vae.ipynb | 367 +++++++++++ vision/VAE/vae.jl | 99 +++ vision/VGG/VGG16.jl | 1 - vision/compositionalPatternNetwork/cppn.ipynb | 42 +- vision/mnist/vae.jl | 67 -- 8 files changed, 1081 insertions(+), 89 deletions(-) create mode 100644 vision/VAE/Manifest.toml create mode 100644 vision/VAE/Project.toml create mode 100644 vision/VAE/README.md create mode 100644 vision/VAE/vae.ipynb create mode 100644 vision/VAE/vae.jl delete mode 100644 vision/mnist/vae.jl diff --git a/vision/VAE/Manifest.toml b/vision/VAE/Manifest.toml new file mode 100644 index 000000000..d35de90e9 --- /dev/null +++ b/vision/VAE/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/VAE/Project.toml b/vision/VAE/Project.toml new file mode 100644 index 000000000..23178a679 --- /dev/null +++ b/vision/VAE/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/VAE/README.md b/vision/VAE/README.md new file mode 100644 index 000000000..ce5a7edfe --- /dev/null +++ b/vision/VAE/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/VAE/vae.ipynb b/vision/VAE/vae.ipynb new file mode 100644 index 000000000..87d6560e1 --- /dev/null +++ b/vision/VAE/vae.ipynb @@ -0,0 +1,367 @@ +{ + "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": "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": "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": "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": "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": "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": "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": "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/VAE/vae.jl b/vision/VAE/vae.jl new file mode 100644 index 000000000..377ad40c9 --- /dev/null +++ b/vision/VAE/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/VGG/VGG16.jl b/vision/VGG/VGG16.jl index 1c321f9f0..a62fcac8e 100644 --- a/vision/VGG/VGG16.jl +++ b/vision/VGG/VGG16.jl @@ -52,7 +52,6 @@ double_conv(in_channels, out_channels) = ( # - ... operator will help us unroll the previously defined blocks # %% -collect(Iterators.repeated(conv_block(256, 256),3)) # %% diff --git a/vision/compositionalPatternNetwork/cppn.ipynb b/vision/compositionalPatternNetwork/cppn.ipynb index a6c335c9d..d3f14dbab 100644 --- a/vision/compositionalPatternNetwork/cppn.ipynb +++ b/vision/compositionalPatternNetwork/cppn.ipynb @@ -23,7 +23,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -42,7 +42,7 @@ "text/plain": "262144" }, "metadata": {}, - "execution_count": 3 + "execution_count": 4 } ], "source": [ @@ -64,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -73,7 +73,7 @@ "text/plain": "cast (generic function with 1 method)" }, "metadata": {}, - "execution_count": 4 + "execution_count": 2 } ], "source": [ @@ -104,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -113,7 +113,7 @@ "text/plain": "unit (generic function with 4 methods)" }, "metadata": {}, - "execution_count": 6 + "execution_count": 45 } ], "source": [ @@ -122,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -131,7 +131,7 @@ "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": 12 + "execution_count": 46 } ], "source": [ @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -156,7 +156,7 @@ "text/plain": "getColorAt (generic function with 1 method)" }, "metadata": {}, - "execution_count": 13 + "execution_count": 47 } ], "source": [ @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -182,7 +182,7 @@ "text/plain": "batch (generic function with 1 method)" }, "metadata": {}, - "execution_count": 15 + "execution_count": 48 } ], "source": [ @@ -202,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -211,7 +211,7 @@ "text/plain": "getImage (generic function with 1 method)" }, "metadata": {}, - "execution_count": 16 + "execution_count": 49 } ], "source": [ @@ -226,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -235,7 +235,7 @@ "text/plain": "saveImg (generic function with 2 methods)" }, "metadata": {}, - "execution_count": 17 + "execution_count": 50 } ], "source": [ @@ -255,7 +255,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 51, "metadata": { "tags": [] }, @@ -263,11 +263,11 @@ { "output_type": "execute_result", "data": { - "text/plain": "10-element Array{Array{Gray{Float64},2},1}:\n [Gray{Float64}(0.2521996716071073) Gray{Float64}(0.25208851762208667) … Gray{Float64}(0.0015289917006011853) Gray{Float64}(0.0015448003400139547); Gray{Float64}(0.25239783981898306) Gray{Float64}(0.25229741836939806) … Gray{Float64}(0.0015409862430406161) Gray{Float64}(0.0015556662740844232); … ; Gray{Float64}(0.0017829869376063436) Gray{Float64}(0.0026525768972253706) … Gray{Float64}(2.5223646445120956e-5) Gray{Float64}(2.47288565856985e-5); Gray{Float64}(0.0021263943914968273) Gray{Float64}(0.0034270737238509975) … Gray{Float64}(2.5486151197834786e-5) Gray{Float64}(2.4966840185825434e-5)]\n [Gray{Float64}(0.04308058429138164) Gray{Float64}(0.04298489327583355) … Gray{Float64}(0.02395747412844401) Gray{Float64}(0.01825646521918251); Gray{Float64}(0.042357330642080644) Gray{Float64}(0.04226691210935509) … Gray{Float64}(0.026345335774048913) Gray{Float64}(0.020041252132139604); … ; Gray{Float64}(0.003412506038343691) Gray{Float64}(0.002221820144178228) … Gray{Float64}(0.0018362171855862831) Gray{Float64}(0.0018332075817697573); Gray{Float64}(0.002435270554345871) Gray{Float64}(0.001489592740363692) … Gray{Float64}(0.0018386287049532927) Gray{Float64}(0.0018355919756633853)]\n [Gray{Float64}(0.014298084086568122) Gray{Float64}(0.014324288214250564) … Gray{Float64}(0.9911107714992583) Gray{Float64}(0.9911459570024385); Gray{Float64}(0.014186650772934082) Gray{Float64}(0.01420328980281595) … Gray{Float64}(0.9910717171717492) Gray{Float64}(0.9911808390164447); … ; Gray{Float64}(0.007993432967378073) Gray{Float64}(0.007965210499122834) … Gray{Float64}(0.9995315968561617) Gray{Float64}(0.9995757652869915); Gray{Float64}(0.007982785748163017) Gray{Float64}(0.007955710258358556) … Gray{Float64}(0.9996836003825987) Gray{Float64}(0.9997056943263476)]\n [Gray{Float64}(0.015536578113201641) Gray{Float64}(0.014992500787099152) … Gray{Float64}(0.25074936822968935) Gray{Float64}(0.24315139994226095); Gray{Float64}(0.01636157410929065) Gray{Float64}(0.015775227066491745) … Gray{Float64}(0.2477865051090734) Gray{Float64}(0.24043556827024629); … ; Gray{Float64}(0.7550746838221093) Gray{Float64}(0.7707165960236805) … Gray{Float64}(6.237419400537261e-5) Gray{Float64}(6.22342831979618e-5); Gray{Float64}(0.7583733549015652) Gray{Float64}(0.7744211567286908) … Gray{Float64}(6.244808635589365e-5) Gray{Float64}(6.230425840066295e-5)]\n [Gray{Float64}(0.40349708429990105) Gray{Float64}(0.39594331940546873) … Gray{Float64}(0.7112214318795447) Gray{Float64}(0.9266997646159046); Gray{Float64}(0.4058746480975122) Gray{Float64}(0.39841189045429143) … Gray{Float64}(0.7563153862749679) Gray{Float64}(0.9583061863052459); … ; Gray{Float64}(0.2593485036863934) Gray{Float64}(0.24234234961321183) … Gray{Float64}(5.04895929519495e-5) Gray{Float64}(5.055041024670008e-5); Gray{Float64}(0.26511931629309704) Gray{Float64}(0.24818105377582633) … Gray{Float64}(5.04997816038374e-5) Gray{Float64}(5.056025343106645e-5)]\n [Gray{Float64}(0.011988700904424852) Gray{Float64}(0.012381599135965416) … Gray{Float64}(0.21665849661980888) Gray{Float64}(0.21069024138460954); Gray{Float64}(0.011840679190036087) Gray{Float64}(0.012211270644579563) … Gray{Float64}(0.2137690672860282) Gray{Float64}(0.2077362977789327); … ; Gray{Float64}(0.41743798122440623) Gray{Float64}(0.37715856994616664) … Gray{Float64}(5.65624834875122e-5) Gray{Float64}(5.724315774770719e-5); Gray{Float64}(0.4192879001144961) Gray{Float64}(0.37915739484747346) … Gray{Float64}(5.699018761016964e-5) Gray{Float64}(5.7715173969834814e-5)]\n [Gray{Float64}(0.5274539672626967) Gray{Float64}(0.6078297427476608) … Gray{Float64}(0.9971539222363504) Gray{Float64}(0.9971358005395428); Gray{Float64}(0.49660883341051043) Gray{Float64}(0.5858615612968465) … Gray{Float64}(0.9971146043013612) Gray{Float64}(0.9971498841802217); … ; Gray{Float64}(0.334778955711171) Gray{Float64}(0.3626231735964442) … Gray{Float64}(5.103743748029504e-5) Gray{Float64}(5.106829160945218e-5); Gray{Float64}(0.34176599876498104) Gray{Float64}(0.36960942276096265) … Gray{Float64}(5.109449768526464e-5) Gray{Float64}(5.112493782639378e-5)]\n [Gray{Float64}(0.09942807535185516) Gray{Float64}(0.10269334284759067) … Gray{Float64}(4.4263681912655106e-5) Gray{Float64}(4.396736472205468e-5); Gray{Float64}(0.09946479082476775) Gray{Float64}(0.10271394900518027) … Gray{Float64}(4.402928393718721e-5) Gray{Float64}(4.3745394598599085e-5); … ; Gray{Float64}(0.9999096607353399) Gray{Float64}(0.9999048956799765) … Gray{Float64}(0.0007687601399143501) Gray{Float64}(0.0006986173881198039); Gray{Float64}(0.9999075276834276) Gray{Float64}(0.9999027976719367) … Gray{Float64}(0.0007843822193858346) Gray{Float64}(0.0007081345928318678)]\n [Gray{Float64}(0.3128185787267912) Gray{Float64}(0.31925348550338706) … Gray{Float64}(0.0017067946350244642) Gray{Float64}(0.0017092982686498363); Gray{Float64}(0.3112719474509596) Gray{Float64}(0.3179476059393161) … Gray{Float64}(0.0017101118545847164) Gray{Float64}(0.0017126693049325222); … ; Gray{Float64}(0.10206570081006515) Gray{Float64}(0.1369357348134079) … Gray{Float64}(3.0108501936791908e-5) Gray{Float64}(2.9429901574261386e-5); Gray{Float64}(0.11611197005304527) Gray{Float64}(0.15208073341651163) … Gray{Float64}(3.0386762741253214e-5) Gray{Float64}(2.9706981745823352e-5)]\n [Gray{Float64}(0.9139554840092061) Gray{Float64}(0.9268222540667976) … Gray{Float64}(0.6739474146712492) Gray{Float64}(0.6727704844839109); Gray{Float64}(0.9158487702719089) Gray{Float64}(0.9231819529375643) … Gray{Float64}(0.672909516787164) Gray{Float64}(0.671720138604213); … ; Gray{Float64}(0.0006547176463694403) Gray{Float64}(0.0006339610402856328) … Gray{Float64}(7.760013279088737e-5) Gray{Float64}(7.733330843616922e-5); Gray{Float64}(0.0006209573405352554) Gray{Float64}(0.000607837698818018) … Gray{Float64}(7.799381741515829e-5) Gray{Float64}(7.773003638801709e-5)]", - "text/html": "
                  (a vector displayed as a row to save space)
                  " + "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": 21 + "execution_count": 51 } ], "source": [ 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) From 79b8002270a0e210ab8702e5383328fc3e3d5f3d Mon Sep 17 00:00:00 2001 From: SubhadityMukherjee Date: Wed, 12 Aug 2020 13:20:34 +0400 Subject: [PATCH 7/7] refactored Vision fully --- .../60-minute-blitz.jl | 0 .../Manifest.toml | 0 .../Project.toml | 0 vision/{VAE => Auto Encoder}/Manifest.toml | 0 vision/{VAE => Auto Encoder}/Project.toml | 0 vision/Auto Encoder/README.md | 3 + vision/Auto Encoder/autoencoder.ipynb | 184 ++++++ vision/Auto Encoder/autoencoder.jl | 81 +++ .../Manifest.toml | 0 .../Project.toml | 0 .../README.md | 0 .../cppn.ipynb | 0 .../cppn.jl | 0 .../Manifest.toml | 0 .../Project.toml | 0 vision/Multi Layer Perceptron/README.md | 3 + vision/Multi Layer Perceptron/mlp.ipynb | 275 ++++++++ .../{mnist => Multi Layer Perceptron}/mlp.jl | 61 +- .../Manifest.toml | 528 +++++++++++++++ .../Project.toml | 3 + .../Compositional Pattern Network/README.md | 5 + .../Compositional Pattern Network/cppn.ipynb | 285 ++++++++ .../VGG/Compositional Pattern Network/cppn.jl | 84 +++ .../VGG/Multi Layer Perceptron/Manifest.toml | 582 ++++++++++++++++ .../VGG/Multi Layer Perceptron/Project.toml | 8 + vision/VGG/Multi Layer Perceptron/README.md | 3 + vision/VGG/Multi Layer Perceptron/mlp.ipynb | 275 ++++++++ vision/VGG/Multi Layer Perceptron/mlp.jl | 88 +++ .../Variational Auto Encoder/Manifest.toml | 582 ++++++++++++++++ .../VGG/Variational Auto Encoder/Project.toml | 8 + .../Variational Auto Encoder}/README.md | 0 .../Variational Auto Encoder}/vae.ipynb | 49 ++ .../Variational Auto Encoder}/vae.jl | 0 vision/{ => VGG}/mnist/.gitignore | 0 vision/VGG/mnist/Manifest.toml | 582 ++++++++++++++++ vision/VGG/mnist/Project.toml | 8 + vision/{ => VGG}/mnist/autoencoder.jl | 0 vision/{ => VGG}/mnist/cuda/Manifest.toml | 0 vision/{ => VGG}/mnist/cuda/Project.toml | 0 vision/Variational Auto Encoder/Manifest.toml | 582 ++++++++++++++++ vision/Variational Auto Encoder/Project.toml | 8 + vision/Variational Auto Encoder/README.md | 4 + vision/Variational Auto Encoder/vae.ipynb | 416 ++++++++++++ vision/Variational Auto Encoder/vae.jl | 99 +++ vision/cuda/Manifest.toml | 624 ++++++++++++++++++ vision/cuda/Project.toml | 9 + vision/mnist/conv.jl | 126 ---- 47 files changed, 5434 insertions(+), 131 deletions(-) rename {tutorials => Introduction to Flux}/60-minute-blitz.jl (100%) rename {tutorials => Introduction to Flux}/Manifest.toml (100%) rename {tutorials => Introduction to Flux}/Project.toml (100%) rename vision/{VAE => Auto Encoder}/Manifest.toml (100%) rename vision/{VAE => Auto Encoder}/Project.toml (100%) create mode 100644 vision/Auto Encoder/README.md create mode 100644 vision/Auto Encoder/autoencoder.ipynb create mode 100644 vision/Auto Encoder/autoencoder.jl rename vision/{compositionalPatternNetwork => Compositional Pattern Network}/Manifest.toml (100%) rename vision/{compositionalPatternNetwork => Compositional Pattern Network}/Project.toml (100%) rename vision/{compositionalPatternNetwork => Compositional Pattern Network}/README.md (100%) rename vision/{compositionalPatternNetwork => Compositional Pattern Network}/cppn.ipynb (100%) rename vision/{compositionalPatternNetwork => Compositional Pattern Network}/cppn.jl (100%) rename vision/{mnist => Multi Layer Perceptron}/Manifest.toml (100%) rename vision/{mnist => Multi Layer Perceptron}/Project.toml (100%) create mode 100644 vision/Multi Layer Perceptron/README.md create mode 100644 vision/Multi Layer Perceptron/mlp.ipynb rename vision/{mnist => Multi Layer Perceptron}/mlp.jl (61%) create mode 100644 vision/VGG/Compositional Pattern Network/Manifest.toml create mode 100644 vision/VGG/Compositional Pattern Network/Project.toml create mode 100644 vision/VGG/Compositional Pattern Network/README.md create mode 100644 vision/VGG/Compositional Pattern Network/cppn.ipynb create mode 100644 vision/VGG/Compositional Pattern Network/cppn.jl create mode 100644 vision/VGG/Multi Layer Perceptron/Manifest.toml create mode 100644 vision/VGG/Multi Layer Perceptron/Project.toml create mode 100644 vision/VGG/Multi Layer Perceptron/README.md create mode 100644 vision/VGG/Multi Layer Perceptron/mlp.ipynb create mode 100644 vision/VGG/Multi Layer Perceptron/mlp.jl create mode 100644 vision/VGG/Variational Auto Encoder/Manifest.toml create mode 100644 vision/VGG/Variational Auto Encoder/Project.toml rename vision/{VAE => VGG/Variational Auto Encoder}/README.md (100%) rename vision/{VAE => VGG/Variational Auto Encoder}/vae.ipynb (96%) rename vision/{VAE => VGG/Variational Auto Encoder}/vae.jl (100%) rename vision/{ => VGG}/mnist/.gitignore (100%) create mode 100644 vision/VGG/mnist/Manifest.toml create mode 100644 vision/VGG/mnist/Project.toml rename vision/{ => VGG}/mnist/autoencoder.jl (100%) rename vision/{ => VGG}/mnist/cuda/Manifest.toml (100%) rename vision/{ => VGG}/mnist/cuda/Project.toml (100%) create mode 100644 vision/Variational Auto Encoder/Manifest.toml create mode 100644 vision/Variational Auto Encoder/Project.toml create mode 100644 vision/Variational Auto Encoder/README.md create mode 100644 vision/Variational Auto Encoder/vae.ipynb create mode 100644 vision/Variational Auto Encoder/vae.jl create mode 100644 vision/cuda/Manifest.toml create mode 100644 vision/cuda/Project.toml delete mode 100644 vision/mnist/conv.jl 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/VAE/Manifest.toml b/vision/Auto Encoder/Manifest.toml similarity index 100% rename from vision/VAE/Manifest.toml rename to vision/Auto Encoder/Manifest.toml diff --git a/vision/VAE/Project.toml b/vision/Auto Encoder/Project.toml similarity index 100% rename from vision/VAE/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/compositionalPatternNetwork/Manifest.toml b/vision/Compositional Pattern Network/Manifest.toml similarity index 100% rename from vision/compositionalPatternNetwork/Manifest.toml rename to vision/Compositional Pattern Network/Manifest.toml diff --git a/vision/compositionalPatternNetwork/Project.toml b/vision/Compositional Pattern Network/Project.toml similarity index 100% rename from vision/compositionalPatternNetwork/Project.toml rename to vision/Compositional Pattern Network/Project.toml diff --git a/vision/compositionalPatternNetwork/README.md b/vision/Compositional Pattern Network/README.md similarity index 100% rename from vision/compositionalPatternNetwork/README.md rename to vision/Compositional Pattern Network/README.md diff --git a/vision/compositionalPatternNetwork/cppn.ipynb b/vision/Compositional Pattern Network/cppn.ipynb similarity index 100% rename from vision/compositionalPatternNetwork/cppn.ipynb rename to vision/Compositional Pattern Network/cppn.ipynb diff --git a/vision/compositionalPatternNetwork/cppn.jl b/vision/Compositional Pattern Network/cppn.jl similarity index 100% rename from vision/compositionalPatternNetwork/cppn.jl rename to vision/Compositional Pattern Network/cppn.jl diff --git a/vision/mnist/Manifest.toml b/vision/Multi Layer Perceptron/Manifest.toml similarity index 100% rename from vision/mnist/Manifest.toml rename to vision/Multi Layer Perceptron/Manifest.toml diff --git a/vision/mnist/Project.toml b/vision/Multi Layer Perceptron/Project.toml similarity index 100% rename from vision/mnist/Project.toml rename to vision/Multi Layer Perceptron/Project.toml 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/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/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/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/VAE/README.md b/vision/VGG/Variational Auto Encoder/README.md similarity index 100% rename from vision/VAE/README.md rename to vision/VGG/Variational Auto Encoder/README.md diff --git a/vision/VAE/vae.ipynb b/vision/VGG/Variational Auto Encoder/vae.ipynb similarity index 96% rename from vision/VAE/vae.ipynb rename to vision/VGG/Variational Auto Encoder/vae.ipynb index 87d6560e1..f04775d8e 100644 --- a/vision/VAE/vae.ipynb +++ b/vision/VGG/Variational Auto Encoder/vae.ipynb @@ -32,6 +32,13 @@ "using Images\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initializing MNIST" + ] + }, { "cell_type": "code", "execution_count": 4, @@ -93,6 +100,13 @@ "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, @@ -130,6 +144,13 @@ "g(X) = (h = A(X); (μ(h), logσ(h)))" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Sample latent space" + ] + }, { "cell_type": "code", "execution_count": 9, @@ -169,6 +190,13 @@ "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, @@ -245,6 +273,13 @@ "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, @@ -268,6 +303,13 @@ "end" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Train" + ] + }, { "cell_type": "code", "execution_count": 16, @@ -308,6 +350,13 @@ "end" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Outputs" + ] + }, { "cell_type": "code", "execution_count": 21, diff --git a/vision/VAE/vae.jl b/vision/VGG/Variational Auto Encoder/vae.jl similarity index 100% rename from vision/VAE/vae.jl rename to vision/VGG/Variational Auto Encoder/vae.jl 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/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