Keras_HED
Keras_HED copied to clipboard
How do i run this?
What is the necessary configuration needed?
Hi,friend!Have you solved the issue ?I also have no ideas how to run it.
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.
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)
Thank you very much!
Is that working with your own images? @JingangLang @jaiprasadreddy
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/
What kinf of files does it need to train this model? What Dataset is used on this implementation?
You can find it in http://vcl.ucsd.edu/hed/HED-BSDS. @HarkDev
@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)
@arnavpuri115 I didn't understand your question. what exactly does it mean by not getting the output.?
@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/.
Hmmm... Where to get the training examples?
How to delete pdb?
下载仓库。在文件HED_data_parser.py中添加列表文件的路径(列表文件空间用img和gnd true分隔),以及包含图像的文件夹。
- 删除main_segmentation.py文件中的pdb(python调试器)跟踪集。
- 运行文件main_segmentation,它将开始训练。
how to delete pdb?
Hi, where can I find the file "vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5" needed as starting weights for the training?
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
@ravip18596 Thank you!