smallcorgi / Faster-RCNN_TF

Faster-RCNN in Tensorflow
MIT License
2.34k stars 1.12k forks source link

TypeError: 'float' object cannot be interpreted as an integer #287

Open Dennis-YB opened 6 years ago

Dennis-YB commented 6 years ago

my python is 3.5,i use the 2to3.py to convert this program,i did the demo.py ,i want to train,when i follow the read me ,there are some errors.

First one is in def load():

  1. data_dict` = np.load(data_path).item() i change it to data_dict = np.load(data_path,encoding="latin1").item()

but the second question is when run it ,the error tell me that 'float' object cannot be interpreted as an integer,why? Who can help me

Loading pretrained model weights from data/pretrain_model/VGG_imagenet.npy assign pretrain model biases to conv5_1 assign pretrain model weights to conv5_1 assign pretrain model biases to conv4_1 assign pretrain model weights to conv4_1 assign pretrain model biases to conv1_1 assign pretrain model weights to conv1_1 assign pretrain model biases to conv2_1 assign pretrain model weights to conv2_1 assign pretrain model biases to conv4_2 assign pretrain model weights to conv4_2 assign pretrain model biases to conv3_3 assign pretrain model weights to conv3_3 assign pretrain model biases to conv3_2 assign pretrain model weights to conv3_2 assign pretrain model biases to conv3_1 assign pretrain model weights to conv3_1 assign pretrain model biases to conv5_3 assign pretrain model weights to conv5_3 assign pretrain model biases to conv1_2 assign pretrain model weights to conv1_2 assign pretrain model biases to conv4_3 assign pretrain model weights to conv4_3 ignore fc8 ignore fc8 assign pretrain model biases to fc6 assign pretrain model weights to fc6 assign pretrain model biases to fc7 assign pretrain model weights to fc7 assign pretrain model biases to conv5_2 assign pretrain model weights to conv5_2 assign pretrain model biases to conv2_2 assign pretrain model weights to conv2_2 2018-04-13 13:22:51.333218: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: TypeError: 'float' object cannot be interpreted as an integer 2018-04-13 13:22:51.360653: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: TypeError: 'float' object cannot be interpreted as an integer [[Node: roi-data/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](rpn_rois/_105, _arg_Placeholder_2_0_2, roi-data/PyFunc/input_2)]] 2018-04-13 13:22:51.360714: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: TypeError: 'float' object cannot be interpreted as an integer [[Node: roi-data/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](rpn_rois/_105, _arg_Placeholder_2_0_2, roi-data/PyFunc/input_2)]] Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1139, in _do_call return fn(*args) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1121, in _run_fn status, run_metadata) File "/usr/lib/python3.5/contextlib.py", line 66, in exit next(self.gen) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: TypeError: 'float' object cannot be interpreted as an integer [[Node: roi-data/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](rpn_rois/_105, _arg_Placeholder_2_0_2, roi-data/PyFunc/input_2)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./tools/train_net.py", line 96, in max_iters=args.max_iters) File "/home/dennis/Faster-RCNN_TF/tools/../lib/fast_rcnn/train.py", line 264, in train_net sw.train_model(sess, max_iters) File "/home/dennis/Faster-RCNN_TF/tools/../lib/fast_rcnn/train.py", line 178, in train_model run_metadata=run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 789, in run run_metadata_ptr) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 997, in _run feed_dict_string, options, run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1132, in _do_run target_list, options, run_metadata) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1152, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: TypeError: 'float' object cannot be interpreted as an integer [[Node: roi-data/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](rpn_rois/_105, _arg_Placeholder_2_0_2, roi-data/PyFunc/input_2)]]

Caused by op 'roi-data/PyFunc', defined at: File "./tools/train_net.py", line 91, in network = get_network(args.network_name) File "/home/dennis/Faster-RCNN_TF/tools/../lib/networks/factory.py", line 30, in get_network return networks.VGGnet_train() File "/home/dennis/Faster-RCNN_TF/tools/../lib/networks/VGGnet_train.py", line 20, in init self.setup() File "/home/dennis/Faster-RCNN_TF/tools/../lib/networks/VGGnet_train.py", line 77, in setup .proposal_target_layer(n_classes,name = 'roi-data')) File "/home/dennis/Faster-RCNN_TF/tools/../lib/networks/network.py", line 25, in layer_decorated layer_output = op(self, layer_input, *args, **kwargs) File "/home/dennis/Faster-RCNN_TF/tools/../lib/networks/network.py", line 189, in proposal_target_layer rois,labels,bbox_targets,bbox_inside_weights,bbox_outside_weights = tf.py_func(proposal_target_layer_py,[input[0],input[1],classes],[tf.float32,tf.float32,tf.float32,tf.float32,tf.float32]) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/script_ops.py", line 198, in py_func input=inp, token=token, Tout=Tout, name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_script_ops.py", line 38, in _py_func name=name) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2506, in create_op original_op=self._default_original_op, op_def=op_def) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1269, in init self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): TypeError: 'float' object cannot be interpreted as an integer [[Node: roi-data/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], token="pyfunc_2", _device="/job:localhost/replica:0/task:0/cpu:0"](rpn_rois/_105, _arg_Placeholder_2_0_2, roi-data/PyFunc/input_2)]]

A-Rain commented 6 years ago

I met the same problem as yours, have you ever solved it?

longzeyilang commented 6 years ago

I met the same problem as yours, have you ever solved it?

longzeyilang commented 6 years ago

@Dennis-YB Change numpy version to 1.11 does not work. The above problem and https://github.com/smallcorgi/Faster-RCNN_TF/issues/231 are not the same problem

YCIrving commented 6 years ago

I met the same problem with #231, instead of changing the version to 1.11, I modified the code in _lib/rpn_msr/proposal_target_layertf.py, line 138-139:

if bg_inds.size > 0: bg_inds = npr.choice(bg_inds, size=bg_rois_per_this_image, replace=False) to if bg_inds.size > 0: bg_inds = npr.choice(bg_inds, size=int(bg_rois_per_this_image), replace=False)

numpy.random.choice requires the second parameter to be a int type, you have to transform it manually in numpy>1.11

That works for me, try to find and modify the similar function calls in _proposal_target_layertf.py if you still encounter the similar problems :)