lc82111 / Keras_HED

Holistically-Nested Edge Detection in Keras
134 stars 52 forks source link

How do i run this? #1

Open athiselvam opened 7 years ago

athiselvam commented 7 years ago

What is the necessary configuration needed?

JingangLang commented 6 years ago

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

jaiprasadreddy commented 6 years ago

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.

jaiprasadreddy commented 6 years ago

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 commented 6 years ago

Thank you very much!

athiselvam commented 6 years ago

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

jaiprasadreddy commented 6 years ago

yes.. The more simpler way can be

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

JuanuMusic commented 6 years ago

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

JackLongKing commented 6 years ago

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

arnavpuri115 commented 6 years ago

@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 commented 6 years ago

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

ChenCong7375 commented 5 years ago

@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 commented 5 years ago

Hmmm... Where to get the training examples?

sly522 commented 4 years ago

How to delete pdb?

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

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

how to delete pdb?

marza1993 commented 3 years ago

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

ravip18596 commented 3 years ago

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 commented 3 years ago

@ravip18596 Thank you!