microsoft/MaskFlownet

Error in operator maskflownet0_maskflownet_s0_upsample0_reshape_like0

ziqipang opened this issue · 1 comments

Dear all,

I am recently trying to use the code to do some inference of my own, and I basically use the code in master branch, combine the code in main.py and predict.py. But I have received strange errors during the forward pass of the network. Please tell me if I have got anything wrong. Thank you very much!

My code is as follows:

import os
import sys
import argparse
import json
import yaml
import numpy as np
import mxnet as mx
import cv2

import network.config
from network import get_pipeline

# NOTE: Use Default Value when running
parser = argparse.ArgumentParser()
parser.add_argument('--config', default='MaskFlownet.yaml', type=str)
parser.add_argument('--gpu_device', default='0', type=str)
parser.add_argument('--network', default='MaskFlownet', type=str)
parser.add_argument('--data_folder', type=str, default='./data/')
parser.add_argument('--img_folder', type=str, default='images/')
parser.add_argument('--checkpoint', type=str, default='5adNov03-0005_1000000.params')
args = parser.parse_args()
args.img_folder = os.path.join(args.data_folder, args.img_folder)


def main():
    ctx = [mx.gpu(gpu_id) for gpu_id in map(int, args.gpu_device.split(','))]
    prefix = os.path.dirname(__file__)
    config_file = 'MaskFlownet.yaml'
    config_path = os.path.join(prefix, 'network/config', config_file)
    with open(config_path) as f:
        config = network.config.Reader(yaml.load(f))
    
    pipe = get_pipeline('MaskFlownet', ctx=ctx, config=config)
    checkpoint_path = os.path.join(prefix, 'weights', args.checkpoint)
    pipe.load(checkpoint_path)
    pipe.fix_head()

    pre_img_name = '1.jpg'
    cur_img_name = '2.jpg'
    pre_img_path = os.path.join(args.img_folder, pre_img_name)
    cur_img_path = os.path.join(args.img_folder, cur_img_name)
    # read the image and resize
    h, w = 576, 1024
    pre_img = cv2.imread(pre_img_path)
    pre_img = cv2.resize(pre_img, (w, h))
    cur_img = cv2.imread(cur_img_path)
    cur_img = cv2.resize(cur_img, (w, h))
    
    # Output the shape of images, making sure the size is correct
    # The shapes are both
    print('Image Shapes {:} {:}'.format(pre_img.shape, cur_img.shape))
    flow = list(pipe.predict([pre_img], [cur_img], batch_size=1))[0][0]
    print(flow)
    return


if __name__ == '__main__':
    main()

And my error log is

Default FLAGS..network.flow_multiplier to 1.0
Default FLAGS..network.deform_bias to True
Default FLAGS..network.upfeat_ch to [16, 16, 16, 16]
Default FLAGS..network.flow_multiplier to 1.0
Default FLAGS..network.deform_bias to True
Default FLAGS..network.upfeat_ch to [16, 16, 16, 16]
Default FLAGS..network.mw to [0.005, 0.01, 0.02, 0.08, 0.32]
Default FLAGS..optimizer.q to None
Image Shapes (576, 1024, 3) (576, 1024, 3)
Traceback (most recent call last):
  File "/mnt/truenas/scratch/ziqi.pang/MaskFlowNet/infer.py", line 67, in <module>
    main()
  File "/mnt/truenas/scratch/ziqi.pang/MaskFlowNet/infer.py", line 61, in main
    flow = list(pipe.predict([pre_img], [cur_img], batch_size=1))[0][0]
  File "/mnt/truenas/scratch/ziqi.pang/MaskFlowNet/network/pipeline.py", line 209, in predict
    flow, occ_mask, warped, _ = self.do_batch(img1s, img2s, resize = resize)
  File "/mnt/truenas/scratch/ziqi.pang/MaskFlowNet/network/pipeline.py", line 136, in do_batch
    flows, occ_masks, _ = self.do_batch_mx(img1, img2, resize = resize)
  File "/mnt/truenas/scratch/ziqi.pang/MaskFlowNet/network/pipeline.py", line 131, in do_batch_mx
    pred, flows, warpeds = self.network(img1, img2)
  File "/root/.tspkg/lib/python3/mxnet/gluon/block.py", line 471, in __call__
    return self.forward(*args)
  File "/root/.tspkg/lib/python3/mxnet/gluon/block.py", line 705, in forward
    return self._call_cached_op(x, *args)
  File "/root/.tspkg/lib/python3/mxnet/gluon/block.py", line 612, in _call_cached_op
    out = self._cached_op(*cargs)
  File "/root/.tspkg/lib/python3/mxnet/_ctypes/ndarray.py", line 149, in __call__
    ctypes.byref(out_stypes)))
  File "/root/.tspkg/lib/python3/mxnet/base.py", line 149, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator maskflownet0_maskflownet_s0_upsample0_reshape_like0: [15:34:33] src/operator/tensor/elemwise_unary_op_basic.cc:348: Check failed: (*in_attrs)[0].Size() == (*in_attrs)[1].Size() (1152 vs. 288) Cannot reshape lhs with shape [2,1,18,32]to rhs with shape [1,2,9,16] because they have different size.

Stack trace returned 10 entries:
[bt] (0) /root/.tspkg/lib/libmxnet.so(dmlc::StackTrace[abi:cxx11]()+0x5b) [0x7f2f8ed8507b]
[bt] (1) /root/.tspkg/lib/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x28) [0x7f2f8ed85be8]
[bt] (2) /root/.tspkg/lib/libmxnet.so(+0x15e128a) [0x7f2f8f7fe28a]
[bt] (3) /root/.tspkg/lib/libmxnet.so(+0x2f8b571) [0x7f2f911a8571]
[bt] (4) /root/.tspkg/lib/libmxnet.so(mxnet::exec::InferShape(nnvm::Graph&&, std::vector<nnvm::TShape, std::allocator<nnvm::TShape> >&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x1ada) [0x7f2f911aa72a]
[bt] (5) /root/.tspkg/lib/libmxnet.so(mxnet::imperative::CheckAndInferShape(nnvm::Graph*, std::vector<nnvm::TShape, std::allocator<nnvm::TShape> >&&, bool, std::pair<unsigned int, unsigned int>, std::pair<unsigned int, unsigned int>)+0x13c) [0x7f2f912abdfc]
[bt] (6) /root/.tspkg/lib/libmxnet.so(mxnet::Imperative::CachedOp::GetForwardGraph(bool, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&)+0x548) [0x7f2f9129a5a8]
[bt] (7) /root/.tspkg/lib/libmxnet.so(mxnet::Imperative::CachedOp::Forward(std::shared_ptr<mxnet::Imperative::CachedOp> const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&)+0xb5) [0x7f2f912a23f5]
[bt] (8) /root/.tspkg/lib/libmxnet.so(MXInvokeCachedOp+0xc39) [0x7f2f917c8569]
[bt] (9) /root/.tspkg/lib/libmxnet.so(MXInvokeCachedOpEx+0x3ee) [0x7f2f917c975e]

I have found that the version of my mxnet is too old. After I upgraded my mxnet, the code can run normally.