Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny network modifications #253

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added For Comparison Use.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ The architecture was inspired by [U-Net: Convolutional Networks for Biomedical I

---

Lab work

Modified from zhixuhao version, the current version can be directly deployed locally, debugs the network, etc....


## Overview

### Data
Expand Down
14 changes: 11 additions & 3 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import glob
import skimage.io as io
import skimage.transform as trans
import cv2

Sky = [128,128,128]
Building = [128,0,0]
Expand Down Expand Up @@ -119,6 +120,13 @@ def labelVisualize(num_class,color_dict,img):


def saveResult(save_path,npyfile,flag_multi_class = False,num_class = 2):
for i,item in enumerate(npyfile):
img = labelVisualize(num_class,COLOR_DICT,item) if flag_multi_class else item[:,:,0]
io.imsave(os.path.join(save_path,"%d_predict.png"%i),img)
for i, item in enumerate(npyfile):
img = labelVisualize(num_class, COLOR_DICT, item) if flag_multi_class else item[:, :, 0]
#print(img) ## ex. [[0.16509348 0.08227982 ... 0.07113015]
img = (img > 0.5).astype(np.uint8) # .reshape(256, 256)
#print(img) ## ex. [[ 0 0 0 0 ... 1 1 1 ]]
img = (img * 255)
#print(img) ## ex. [[0 0 00 ... 255 255 255]]
# img = labelVisualize(num_class,COLOR_DICT,item) if flag_multi_class else item[:,:,0]
# io.imsave(os.path.join(save_path,"%d_predict.png"%i),img)
cv2.imwrite(os.path.join(save_path, "%d_predict.png" % i), img)
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from model import *
from data import *
import warnings
warnings.filterwarnings('ignore')

#os.environ["CUDA_VISIBLE_DEVICES"] = "0"

Expand All @@ -15,8 +17,7 @@

model = unet()
model_checkpoint = ModelCheckpoint('unet_membrane.hdf5', monitor='loss',verbose=1, save_best_only=True)
model.fit_generator(myGene,steps_per_epoch=300,epochs=1,callbacks=[model_checkpoint])

model.fit_generator(myGene,steps_per_epoch=300,epochs=5,callbacks=[model_checkpoint])
testGene = testGenerator("data/membrane/test")
results = model.predict_generator(testGene,30,verbose=1)
saveResult("data/membrane/test",results)
saveResult("data/membrane/result",results)
2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def unet(pretrained_weights = None,input_size = (256,256,1)):
conv9 = Conv2D(2, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv9)
conv10 = Conv2D(1, 1, activation = 'sigmoid')(conv9)

model = Model(input = inputs, output = conv10)
model = Model(inputs,conv10)

model.compile(optimizer = Adam(lr = 1e-4), loss = 'binary_crossentropy', metrics = ['accuracy'])

Expand Down