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

How do i run this? #1

Open
athiselvam opened this issue Nov 14, 2017 · 16 comments
Open

How do i run this? #1

athiselvam opened this issue Nov 14, 2017 · 16 comments

Comments

@athiselvam
Copy link

What is the necessary configuration needed?

@JingangLang
Copy link

Hi,friend!Have you solved the issue ?I also have no ideas how to run it.

@jaiprasadreddy
Copy link

Download the repo. Add the path for the list file(list file space separated with img and gnd truth) and also the folder containing images in the file HED_data_parser.py.

  • Remove the pdb(python debugger) trace set in the main_segmentation.py file.
  • Run the file main_segmentation and it will start the training.

@jaiprasadreddy
Copy link

jaiprasadreddy commented Dec 25, 2017

To get the output for the Trained model. Try this code.

from future import print_function
import os
from src.utils.HED_data_parser import DataParser
from src.networks.hed import hed
from keras.utils import plot_model
from keras import backend as K
from keras import callbacks
import numpy as np
import glob
from PIL import Image
import cv2

test = glob.glob('images/*')
if name == "main":
#environment
K.set_image_data_format('channels_last')
K.image_data_format()
os.environ["CUDA_VISIBLE_DEVICES"]= '0'
if not os.path.isdir(model_dir): os.makedirs(model_dir)

# model
model = hed()
# plot_model(model, to_file=os.path.join(model_dir, 'model.pdf'), show_shapes=True)

# training
# call backs
model.load_weights('checkpoint.03-0.31.hdf5')
# train_history = model.predict()
for image in test:
    name = image.split('/')[-1]
    x_batch = []
    im = Image.open(image)
    im = im.resize((480,480))
    im = np.array(im, dtype=np.float32)
    im = im[..., ::-1]  # RGB 2 BGR
    R = im[..., 0].mean()
    G = im[..., 1].mean()
    B = im[..., 2].mean()
    im[..., 0] -= R
    im[..., 1] -= G
    im[..., 2] -= B
    x_batch.append(im)
    x_batch = np.array(x_batch, np.float32)
    prediction = model.predict(x_batch)
    mask = np.zeros_like(im[:,:,0])
    for i in xrange(len(prediction)):
        mask += np.reshape(prediction[i],(480,480))
    ret,mask = cv2.threshold(mask,np.mean(mask)+1.2*np.std(mask),255,cv2.THRESH_BINARY)
    cv2.imwrite("output/%s"%name,mask)

@JingangLang
Copy link

Thank you very much!

@athiselvam
Copy link
Author

Is that working with your own images? @JingangLang @jaiprasadreddy

@jaiprasadreddy
Copy link

yes..
The more simpler way can be

  • During training save the model to the json.
  • load model during inference or testing from json and predict it on image.

check this link - https://machinelearningmastery.com/save-load-keras-deep-learning-models/

@JuanuMusic
Copy link

What kinf of files does it need to train this model?
What Dataset is used on this implementation?

@JackLongKing
Copy link

You can find it in http://vcl.ucsd.edu/hed/HED-BSDS. @harkdev

@arnavpuri115
Copy link

@jaiprasadreddy

I have tried to reproduce the test code by making a new python file and putting it in the Keras-HED master folder named test file. After I run it, the code gets compiled but there is no output. What am I doing wrong?

Here's how I have used the code.

#from future import print_function
import os
from src.utils.HED_data_parser import DataParser
from src.networks.hed import hed
from keras.utils import plot_model
from keras import backend as K
from keras import callbacks
import numpy as np
import glob
from PIL import Image
import cv2

test = glob.glob('images/*')
if name == "main":
model_name = 'HEDSeg'
model_dir = os.path.join('checkpoints', model_name)
csv_fn = os.path.join(model_dir, 'train_log.csv')
checkpoint_fn = os.path.join(model_dir, 'checkpoint.01-0.14.hdf5')
K.set_image_data_format('channels_last')
K.image_data_format()
os.environ["CUDA_VISIBLE_DEVICES"]= '0'
if not os.path.isdir(model_dir):
os.makedirs(model_dir)

model

model = hed()
plot_model(model, to_file=os.path.join(model_dir, 'model.pdf'), show_shapes=True)

training

call backs

model.load_weights('checkpoint.01-0.14.hdf5')

train_history = model.predict()

for image in test:
name = image.split('/')[-1]
x_batch = []
im = Image.open(image)
im = im.resize((480,480))
im = np.array(im, dtype=np.float32)
im = im[..., ::-1] # RGB 2 BGR
R = im[..., 0].mean()
G = im[..., 1].mean()
B = im[..., 2].mean()
im[..., 0] -= R
im[..., 1] -= G
im[..., 2] -= B
x_batch.append(im)
x_batch = np.array(x_batch, np.float32)
prediction = model.predict(x_batch)
mask = np.zeros_like(im[:,:,0])
for i in xrange(len(prediction)):
mask += np.reshape(prediction[i],(480,480))
ret,mask = cv2.threshold(mask,np.mean(mask)+1.2*np.std(mask),255,cv2.THRESH_BINARY)
cv2.imwrite("output/%s"%name,mask)

@jaiprasadreddy
Copy link

@arnavpuri115 I didn't understand your question. what exactly does it mean by not getting the output.?

@ChenCong7375
Copy link

@arnavpuri115 I didn't understand your question. what exactly does it mean by not getting the output.?

there is no output PICS in the folder output/.

@feiyangsuo
Copy link

Hmmm... Where to get the training examples?

@sly522
Copy link

sly522 commented Nov 28, 2019

How to delete pdb?

下载仓库。在文件HED_data_parser.py中添加列表文件的路径(列表文件空间用img和gnd true分隔),以及包含图像的文件夹。

  • 删除main_segmentation.py文件中的pdb(python调试器)跟踪集。
  • 运行文件main_segmentation,它将开始训练。

how to delete pdb?

@marza1993
Copy link

Hi, where can I find the file "vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5" needed as starting weights for the training?

@ravip18596
Copy link

Hi, where can I find the file "vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5" needed as starting weights for the training?

@marza1993 You can download model assets from this release page - https://github.com/fchollet/deep-learning-models/releases/tag/v0.1

@marza1993
Copy link

@ravip18596 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests