Comments (2)
@anjanakumar
Yes, you can see the following example method I provided. The key point is applying opencv VideoCapture to read a video and VideoWriter to save your output result. Modified the code in demo.py. One thing to mention is FLAGS.data_file is the video file path and FLAGS.save_video is a bool value to determine whether save the output video.
def run_my_eval(load_out, output_folder, data_file):
meta_hypes, subhypes, submodules, decoded_logits, sess, image_pl = load_out
seg_softmax = decoded_logits['segmentation']['softmax']
pred_boxes_new = decoded_logits['detection']['pred_boxes_new']
pred_confidences = decoded_logits['detection']['pred_confidences']
eval_list = [seg_softmax, pred_boxes_new, pred_confidences]
def my_preprocess(image):
# define your own method
pass
def my_postprocess(shape, image):
# define your own method
pass
assert os.path.isfile(data_file), \
'file {} does not exist'.format(data_file)
camera = cv2.VideoCapture(data_file)
assert camera.isOpened(), \
'Cannot capture source'
_, frame = camera.read()
height, width, _ = frame.shape
if FLAGS.save_video:
fourcc = cv2.VideoWriter_fourcc(*'XVID')
fps = round(camera.get(cv2.CAP_PROP_FPS))
video_writer = cv2.VideoWriter('video.avi', fourcc, fps, (width, height))
test_constant_input(subhypes)
test_segmentation_input(subhypes)
import utils.train_utils as dec_utils
# buffers for demo in batch
buffer_pre = list()
elapsed = int()
start = timer()
logging.info('Start video prediction.')
while camera.isOpened():
elapsed += 1
_, frame = camera.read()
if frame is None:
logging.info('End of Video')
break
# resize input frame
preprocessed = my_preprocess(frame)
# run one frame predict
feed_dict = {image_pl: preprocessed}
output = sess.run(eval_list, feed_dict=feed_dict)
seg_softmax, pred_boxes_new, pred_confidences = output
# Create Segmentation Overlay
shape = preprocessed.shape
seg_softmax = seg_softmax[:, 1].reshape(shape[0], shape[1])
hard = seg_softmax > 0.5
overlay_image = utils.fast_overlay(preprocessed, hard)
# Draw Detection Boxes
new_img, rects = dec_utils.add_rectangles(
subhypes['detection'], [overlay_image], pred_confidences,
pred_boxes_new, show_removed=False,
use_stitching=True, rnn_len=subhypes['detection']['rnn_len'],
min_conf=0.50, tau=subhypes['detection']['tau'])
postprocessed = my_postprocess(new_img)
# save one frame in ouput video
video_writer.write(postprocessed)
if elapsed % 50 == 0:
logging.info('Speed (fps): {0:3.3f} FPS'.format(
elapsed / (timer() - start)))
logging.info('Video prediction complete. Cost {0:3.3f} sec.'.format(
timer() - start))
logging.info('Save output video file to video.avi')
if FLAGS.save_video:
video_writer.release()
camera.release()
from multinet.
@lujian9328
你好,请问你视频检测成功了吗,这两个函数具体写什么呢【my_preprocess(image),my_postprocess(shape, image)】,看到请回复,谢谢
from multinet.
Related Issues (20)
- No module named 'annolist' HOT 1
- How does Detection/Decoder module work?
- The ftp link to download the vgg16.npy file isn't accessible HOT 1
- About download_data.py HOT 4
- How to train with other models, like resNet, YOLO, SqueezeNet?
- I do not understand the number in paper.(Convolution and concatenated) HOT 2
- AssertionError assert(image_height >= shape[0]) in demo.py
- request for updating the codes HOT 3
- A question
- some errors when do test
- train multinet2.json out of memory seriously
- Does the codes update to v2 now?
- how to trian my dataset on Multinet3 HOT 1
- terminate called after throwing an instance of 'std::bad_alloc'
- ResourceExhaustedError (see above for traceback): OOM when allocating tensor of shape [7,7,512,4096] and type float [[Node: fc6/weights/Adam/Initializer/zeros = Const[dtype=DT_FLOAT, value=Tensor<type: float shape: [7,7,512,4 096] values: [[[0 0 0]]]...>, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]] HOT 1
- subprocess.CalledProcessError: Command returned non-zero exit status -11 HOT 1
- The kitti download url is not accessible now, can not finish running download_data.py HOT 3
- About training HOT 1
- trained model HOT 1
- /bin/bash: makecython++:command not found
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multinet.