Ejemplo n.º 1
0
def flowWarp(img, flow):
    import caffe
    width = img.shape[1]
    height = img.shape[0]

    print 'processing (%dx%d)' % (width, height)

    defFile = tempFilename('.prototxt')
    preprocessFile('/home/ilge/hackathon2/common/prototmp/apply_flow.prototmp', defFile, {'WIDTH': width, 'HEIGHT': height})

    caffe.set_logging_disabled()
    caffe.set_mode_gpu()
    net = caffe.Net(
        defFile,
        caffe.TEST
    )

    os.remove(defFile)

    print 'network forward pass'

    img_input = img[np.newaxis, :, :, :].transpose(0, 3, 1, 2)
    flow_input = flow[np.newaxis, :, :, :].transpose(0, 3, 1, 2)

    net.blobs['image'].reshape(*img_input.shape)
    net.blobs['image'].data[...] = img_input
    net.blobs['flow'].reshape(*flow_input.shape)
    net.blobs['flow'].data[...] = flow_input

    net.forward()
    output = net.blobs['output'].data[...].transpose(0, 2, 3, 1).squeeze()

    return output
Ejemplo n.º 2
0
def flowWarp(img, flow):
    import caffe
    width = img.shape[1]
    height = img.shape[0]

    print 'processing (%dx%d)' % (width, height)

    defFile = tempFilename('.prototxt')
    preprocessFile('/home/ilge/hackathon2/common/prototmp/apply_flow.prototmp',
                   defFile, {
                       'WIDTH': width,
                       'HEIGHT': height
                   })

    caffe.set_logging_disabled()
    caffe.set_mode_gpu()
    net = caffe.Net(defFile, caffe.TEST)

    os.remove(defFile)

    print 'network forward pass'

    img_input = img[np.newaxis, :, :, :].transpose(0, 3, 1, 2)
    flow_input = flow[np.newaxis, :, :, :].transpose(0, 3, 1, 2)

    net.blobs['image'].reshape(*img_input.shape)
    net.blobs['image'].data[...] = img_input
    net.blobs['flow'].reshape(*flow_input.shape)
    net.blobs['flow'].data[...] = flow_input

    net.forward()
    output = net.blobs['output'].data[...].transpose(0, 2, 3, 1).squeeze()

    return output
Ejemplo n.º 3
0
def caffeNet(modelFile=None, prototmp=None, inputs={}, phase=None, logging=False):
    if phase is None: phase=caffe.TEST
    if prototmp is not None:
        modelFile = tempFilename('.prototmp')
        open(modelFile,'w').write(prototmp)

    if not logging: caffe.set_logging_disabled()
    caffe.set_mode_gpu()
    net = caffe.Net(
        modelFile,
        phase
    )

    if prototmp is not None:
        os.remove(modelFile)

    for name, value in inputs.iteritems():
        value = value[np.newaxis, :, :, :].transpose(0, 3, 1, 2)
        net.blobs[name].reshape(*value.shape)
        net.blobs[name].data[...] = value

    return net