Downloading training data
Many of the standard datasets for semantic segmentation have custom licenses and require you to register to download them. We will use https://web.engr.oregonstate.edu/~lif/SegTrack2/SegTrackv2.zip
Fetch the data
Fetch the data
Grab the data and unzip it (it may be slow if you’re hard drive is not an SSD).
In[]:=
rootDir="d:\\users\\dan_f\\Downloads\\SegTrackv2\\SegTrackv2"
Out[]=
d:\users\dan_f\Downloads\SegTrackv2\SegTrackv2
In[]:=
frogImages=FileNames["*.png",FileNameJoin[{rootDir,"JPEGImages","frog"}]];
In[]:=
gtImages=FileNames["*.png",FileNameJoin[{rootDir,"GroundTruth","frog"}]];
In[]:=
tst=Import[frogImages[[1]]]
Out[]=
In[]:=
ImageDimensions[%]
Out[]=
{480,264}
In[]:=
encoder=NetChain[{ConvolutionLayer[2,3,"PaddingSize"->1],Ramp,ConvolutionLayer[2,1],ConvolutionLayer[2,3,"Stride"->2,"PaddingSize"->1]}]
Out[]=
NetChain
In[]:=
decoder=NetChain[{ResizeLayer[{Scaled[2],Scaled[2]}],ConvolutionLayer[2,3,"PaddingSize"->1]}]
Out[]=
NetChain
In[]:=
net=NetGraph[<|"down1"->encoder,"down2"->encoder,"down3"->encoder,"up1"->decoder,"up2"->decoder,"up3"->decoder,"agg"->NetChain[{AggregationLayer[Max,1],ReplicateLayer[1]}]|>,{NetPort["Input"]->"down1","down1"->"down2","down2"->"down3","down3"->"up1","up1"->"up2","up2"->"up3","up3"->"agg"},"Input"->NetEncoder[{"Image",{480,264},"ColorSpace"->"Grayscale"}],"Output"->NetDecoder[{"Image","ColorSpace"->"Grayscale"}]]
Out[]=
NetGraph
In[]:=
net=NetInitialize[net]
Out[]=
NetGraph
In[]:=
trainSet=Table[File[frogImages[[i]]]->File[gtImages[[i]]],{i,1,Length[frogImages]}];
In[]:=
trained=NetTrain[net,RandomChoice[trainSet,10000],TargetDevice"GPU"]
Out[]=
NetGraph
In[]:=
trained[Import@frogImages[[43]]]
Out[]=

