# Data Preparation for TGS Salt Identification

**URL:** <https://discourse.julialang.org/t/data-preparation-for-tgs-salt-identification/63893>\
**Category:** General Usage\
**Tags:** question, flux, machine-learning\
**Created:** [July 1, 2021, 2:19pm UTC](https://discourse.julialang.org/t/data-preparation-for-tgs-salt-identification/63893 "2021-07-01T14:19:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paritosh\_Kr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paritosh_kr/32/26675_2.png) [@Paritosh\_Kr](https://discourse.julialang.org/u/Paritosh_Kr)\
**Post date:** [July 1, 2021, 2:19pm UTC](https://discourse.julialang.org/t/data-preparation-for-tgs-salt-identification/63893/1 "2021-07-01T14:19:22Z")

</div>

I am writing a Unet in Flux.jl for [TGS Salt identification challenge](https://www.kaggle.com/c/tgs-salt-identification-challenge/overview) .  
The data is organised as follows:-  
data/train/images - contains (101x101x3) training images  
data/train/masks - contains (101x101x1) training masks (labels)  
data/train/train.csv - contains name of the training images and their corresponding masks  
My Code is:-

> Blockquote

# This function creates array of shapes X - (101x101x3xn) , Y - (101x101x1xn)

# i.e in the format of (width, height, channel, batch\_size) (w, h, c, n)

function load\_data(train\_df, base\_dir, n,rsize = (101,101))  
img\_dir = “images/”  
mask\_dir = “masks/”  
x= zeros(UInt8,rsize…,3, n) #   
y = zeros(UInt8, rsize…, 1,n)  
count = 1  
for i in train\_df[!, “id”]  
try  
if isfile(string(joinpath(base\_dir, img\_dir, i), “.png”)) && isfile(string(joinpath(base\_dir, mask\_dir, i), “.png”))  
img = load(string(joinpath(base\_dir, img\_dir, i), “.png”))  
img = convert(Image{Gray}, img)  
mask = load(string(joinpath(base\_dir, mask\_dir, i), “.png”))  
img = channelview(img)  
mask = channelview(mask)  
x′ = @view x[:,:,:,count]  
x′ .= img  
y′ = @view y[:,:,:,count]  
y′ .= mask  
append(x,x′)  
append(y, y′)  
count += 1  
end  
catch ArgumentError  
end  
end  
x, y  
end

# The code for the Unet is:-

function Unet()  
c1 = convBlock(3, 6, (3,3))  
c1\_next = convBlock(6,6, (3,3))  
p1 = MaxPool((2, 2))  
c2 = convBlock(6,12, (3,3))  
c2\_next = convBlock(12,12, (3,3))  
p2 = MaxPool((2,2))  
c3 = convBlock(12,25, (3,3))  
c3\_next = convBlock(25,25, (3,3))  
p3 = MaxPool((2,2))  
c4 = convBlock(25,50, (3,3))  
c4\_next = convBlock(50,50, (3,3))  
p4 = MaxPool((2,2))  
ct1 = convTransBlock(101,50, (3,3))  
ct1\_next = convBlock(50,50, (3,3))  
ct2 = convTransBlock(50,25, (3,3))  
ct2\_next = convBlock(25,25, (3,3))  
ct3 = convTransBlock(25,12, (3,3))  
ct3\_next = convBlock(12,12, (3,3))  
ct4 = convTransBlock(12,6, (3,3))  
ct4\_next = convBlock(6,6, (3,3))  
return Chain(  
# \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Conv 1  
c1,  
Dropout(0.1),  
c1\_next,  
p1,  
# \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Conv 2  
c2,  
Dropout(0.1),  
c2\_next,  
p2,  
# \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Conv 3  
c3,  
Dropout(0.2),  
c3\_next,  
p3,  
# \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Conv 4  
c4,  
Dropout(0.2),  
c4\_next,  
p4,  
# \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Conv 5  
convBlock(50,101),  
convBlock(101,101),  
#\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Expand 1  
ct1,  
cat(ct1, c4\_next, dims=4),  
ct1\_next,  
Dropout(0.2),  
ct1\_next,  
#\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_Expand 2  
ct2,  
cat(ct2, c3\_next, dims=4),  
ct2\_next,  
Dropout(0.2),  
ct2\_next,  
#\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_Expand 3  
ct3,  
cat(ct3, c2\_next, dims=4),  
ct3\_next,  
Dropout(0.2),  
ct3\_next,  
#\_\__**Expand 4  
ct4,  
cat(ct4, c1\_next, dims=4),  
ct4\_next,  
Dropout(0.2),  
ct4\_next,  
#**_ Output  
convBlock(6, 1, (1,1)))  
end

# The data preparation and the training code is:-

base\_dir = “data/train/”  
x\_train, y\_train = load\_data(train\_df, base\_dir, 4000)  
train\_data = Flux.Data.DataLoader(x\_train, y\_train, batchsize=10)  
m = Unet()  
p = params(m)  
loss(x, y) = crossentropy(m(x), y)  
opt = ADAM(0.001, (0.9, 0.8))  
epochs = 1  
@epochs epochs Flux.train!(loss, p, train\_data, opt, cb = () → println(“Training”))

On running the code I get the following error:-  
MethodError: objects of type Array{Chain,4} are not callable  
Use square brackets for indexing an Array.

“Please help me! I am not able to move ahead. Please recommend all the edits and changes that should be done in the code.”
