yangliupku / retinanet_detection

vehicle detection using retinanet
29 stars 9 forks source link

encountered errors when running python train_mobilenet.py #1

Closed kaishijeng closed 6 years ago

kaishijeng commented 6 years ago

@yangliupku

I got the following errors when "python train_mobilenet.py --alpha 0.25 --batch-size 8" My tensorflow version is 1.4.0 and keras is from head of github.

/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py:96: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory. "Converting sparse IndexedSlices to a dense Tensor of unknown shape. " Traceback (most recent call last): File "train_mobilenet.py", line 121, in monitor='val_loss', min_delta=0, patience=10, verbose=0, mode='auto') File "build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py", line 87, in wrapper File "build/bdist.linux-x86_64/egg/keras/engine/training.py", line 2015, in fit_generator File "build/bdist.linux-x86_64/egg/keras/engine/training.py", line 990, in _make_train_function File "build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py", line 87, in wrapper File "build/bdist.linux-x86_64/egg/keras/optimizers.py", line 421, in get_updates File "build/bdist.linux-x86_64/egg/keras/optimizers.py", line 73, in get_gradients File "build/bdist.linux-x86_64/egg/keras/backend/tensorflow_backend.py", line 2402, in gradients File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 608, in gradients grad_scope, op, func_call, lambda: grad_fn(op, out_grads)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 374, in _MaybeCompile return grad_fn() # Exit early File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 608, in grad_scope, op, func_call, lambda: grad_fn(op, out_grads)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_grad.py", line 499, in _ReshapeGrad return [array_ops.reshape(grad, array_ops.shape(op.inputs[0])), None] File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3917, in reshape "Reshape", tensor=tensor, shape=shape, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 513, in _apply_op_helper raise err TypeError: Input 'num_segments' of 'UnsortedSegmentSum' Op has type int64 that does not match expected type of int32.

yangliupku commented 6 years ago

HI

Really sorry, I’m still testing the code on my local machine, will need some work to make it easier to run on your dataset..

Best

Yang

On Dec 11, 2017, at 4:37 PM, kaishijeng <notifications@github.com mailto:notifications@github.com> wrote:

@yangliupku https://github.com/yangliupku I got the following errors when "python train_mobilenet.py --alpha 0.25 --batch-size 8" My tensorflow version is 1.4.0 and keras is from head of github.

/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py:96: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory. "Converting sparse IndexedSlices to a dense Tensor of unknown shape. " Traceback (most recent call last): File "train_mobilenet.py", line 121, in monitor='val_loss', min_delta=0, patience=10, verbose=0, mode='auto') File "build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py", line 87, in wrapper File "build/bdist.linux-x86_64/egg/keras/engine/training.py", line 2015, in fit_generator File "build/bdist.linux-x86_64/egg/keras/engine/training.py", line 990, in _make_train_function File "build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py", line 87, in wrapper File "build/bdist.linux-x86_64/egg/keras/optimizers.py", line 421, in get_updates File "build/bdist.linux-x86_64/egg/keras/optimizers.py", line 73, in get_gradients File "build/bdist.linux-x86_64/egg/keras/backend/tensorflow_backend.py", line 2402, in gradients File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 608, in gradients grad_scope, op, func_call, lambda: grad_fn(op, out_grads)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 374, in _MaybeCompile return grad_fn() # Exit early File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 608, in grad_scope, op, func_call, lambda: grad_fn(op, out_grads)) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_grad.py", line 499, in _ReshapeGrad return [array_ops.reshape(grad, array_ops.shape(op.inputs[0])), None] File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3917, in reshape "Reshape", tensor=tensor, shape=shape, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 513, in _apply_op_helper raise err TypeError: Input 'num_segments' of 'UnsortedSegmentSum' Op has type int64 that does not match expected type of int32.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yangliupku/retinanet_detection/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/Abf1j7pqaJQC3I7o-khZn43NIqghwxWOks5s_aCNgaJpZM4Q-Eel.

https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png https://github.com/yangliupku/retinanet_detection https://github.com/yangliupku/retinanet_detection/issues/1

kaishijeng commented 6 years ago

I use the same dataset as yours which is from Udacity annotated driving dataset. Does your code require GPU to run? My system is i7 Intel CPU without GPU.

Thanks,

kaishijeng commented 6 years ago

After I switch to a different PC, I can do training without errors (Not sure the rootcause). However, I encounter an error when trying to load my trained model. Below is the the code I use to load model:

coding: utf-8

import keras import keras.preprocessing.image from keras_retinanet.models.resnet import custom_objects from keras_retinanet.preprocessing.coco import CocoGenerator import matplotlib.pyplot as plt import cv2 import os import numpy as np import time import keras_retinanet.models.mobilenet as mobilenet import tensorflow as tf def get_session(): config = tf.ConfigProto() config.gpu_options.allow_growth = True return tf.Session(config=config)

keras.backend.tensorflow_backend.set_session(get_session())

custom_objects.update({'relu6': mobilenet.relu6, 'DepthwiseConv2D': mobilenet.DepthwiseConv2D})

model = keras.models.load_model('snapshots_last/mobilenet_a0.25_s8_rdc2/mobilenet_a0.25_s8_rdc2_best.h5',c,custom_objects=custom_objects) print(model.summary())

I got the following error:

Traceback (most recent call last): File "./test.py", line 23, in model = keras.models.load_model('snapshots_last/mobilenet_a0.25_s8_rdc2/mobilenet_a0.25_s8_rdc2_best.h5',custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 239, in load_model model = model_from_config(model_config, custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 313, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/layers/init.py", line 54, in deserialize printable_module_name='layer') File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object list(custom_objects.items()))) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2487, in from_config process_layer(layer_data) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2473, in process_layer custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/layers/init.py", line 54, in deserialize printable_module_name='layer') File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 141, in deserialize_keras_object return cls.from_config(config['config']) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1252, in from_config return cls(**config) TypeError: init() takes at least 2 arguments (1 given)

Any idea?

Thanks

kaishijeng commented 6 years ago

@yangliupku

Do you know why I can't load my own trained model with the code below:

model = keras.models.load_model('snapshots_last/mobilenet_a0.25_s8_rdc2/mobilenet_a0.25_s8_rdc2_best.h5',custom_objects=custom_objects)

File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 239, in load_model model = model_from_config(model_config, custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 313, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/layers/init.py", line 54, in deserialize printable_module_name='layer') File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object list(custom_objects.items()))) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2487, in from_config process_layer(layer_data) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2473, in process_layer custom_objects=custom_objects) File "/usr/local/lib/python2.7/dist-packages/keras/layers/init.py", line 54, in deserialize printable_module_name='layer') File "/usr/local/lib/python2.7/dist-packages/keras/utils/generic_utils.py", line 141, in deserialize_keras_object return cls.from_config(config['config']) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 1252, in from_config return cls(**config) TypeError: init() takes at least 2 arguments (1 given)

yangliupku commented 6 years ago

@kaishijeng it's a bug in Keras_resnet.

A work around is to set a default value in batachnorm layer

find ~/.local/lib/pythonX/site-packages/keras_resnet/layers/_batch_normalization.py change the layer definition to:

def init(self, freeze= False, *args, **kwargs):

kaishijeng commented 6 years ago

IT works.

Thanks