reachsumit / deep-unet-for-satellite-image-segmentation

Satellite Imagery Feature Detection with SpaceNet dataset using deep UNet
308 stars 139 forks source link

Assertion error while running train_unet.py #12

Open prativadas opened 5 years ago

prativadas commented 5 years ago

assert len(img.shape) == 3 and img.shape[0] > sz and img.shape[1] > sz and img.shape[0:2] == mask.shape[0:2] this is getting Assertion error while running train_unet.py

how to resolve this?

prativadas commented 5 years ago

when i change this line in train_unet train_xsz = int(3/4 img_m.shape[0]) to this train_xsz = int(img_m.shape[0](0.75)) the error goes away and model starts training

onimonipea commented 4 years ago

I had the same error. My problem was caused by a difference in data structures. The imagery I wanted to train on was already correctly formatted, so I did not need to use numpy.transpose() to get img.shape and mask.shape in the proper order (X, Y, channels). Changing train_unet.py to transpose the data into the correct format should help you clear the assertion check.

v-bryzgalin commented 4 years ago

when i change this line in train_unet train_xsz = int(3/4 img_m.shape[0]) to this train_xsz = int(img_m.shape[0](0.75)) the error goes away and model starts training

Thank you, it was useful!

nacerader commented 4 years ago

Hello , can somone help me please in this code , when i run the Train_unet i get this error :

start train net Generated 4000 patches Generated 1000 patches


InvalidArgumentError Traceback (most recent call last) ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs) 1618 try: -> 1619 c_op = c_api.TF_FinishOperation(op_desc) 1620 except errors.InvalidArgumentError as e:

InvalidArgumentError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_20/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,512].

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in 18 return model 19 ---> 20 train_net() in train_net() 3 x_train, y_train = get_patches(X_DICT_TRAIN, Y_DICT_TRAIN, n_patches=TRAIN_SZ, sz=PATCH_SZ) 4 x_val, y_val = get_patches(X_DICT_VALIDATION, Y_DICT_VALIDATION, n_patches=VAL_SZ, sz=PATCH_SZ) ----> 5 model = get_model() 6 if os.path.isfile(weights_path): 7 model.load_weights(weights_path) in get_model() 1 def get_model(): ----> 2 return unet_model(N_CLASSES, PATCH_SZ, n_channels=N_BANDS, upconv=UPCONV, class_weights=CLASS_WEIGHTS) 3 4 5 weights_path = 'weights' ~\Desktop\Unet\deep-unet-for-satellite-image-segmentation-master\unet_model.py in unet_model(n_classes, im_sz, n_channels, n_filters_start, growth_factor, upconv, class_weights) 44 conv4_1 = Conv2D(n_filters, (3, 3), activation='relu', padding='same')(pool4_1) 45 conv4_1 = Conv2D(n_filters, (3, 3), activation='relu', padding='same')(conv4_1) ---> 46 pool4_2 = MaxPooling2D(pool_size=(2, 2))(conv4_1) 47 pool4_2 = Dropout(droprate)(pool4_2) 48 ~\anaconda3\envs\tf3\lib\site-packages\keras\backend\tensorflow_backend.py in symbolic_fn_wrapper(*args, **kwargs) 73 if _SYMBOLIC_SCOPE.value: 74 with get_graph().as_default(): ---> 75 return func(*args, **kwargs) 76 else: 77 return func(*args, **kwargs) ~\anaconda3\envs\tf3\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs) 487 # Actually call the layer, 488 # collecting output(s), mask(s), and shape(s). --> 489 output = self.call(inputs, **kwargs) 490 output_mask = self.compute_mask(inputs, previous_mask) 491 ~\anaconda3\envs\tf3\lib\site-packages\keras\layers\pooling.py in call(self, inputs) 203 strides=self.strides, 204 padding=self.padding, --> 205 data_format=self.data_format) 206 return output 207 ~\anaconda3\envs\tf3\lib\site-packages\keras\layers\pooling.py in _pooling_function(self, inputs, pool_size, strides, padding, data_format) 266 output = K.pool2d(inputs, pool_size, strides, 267 padding, data_format, --> 268 pool_mode='max') 269 return output 270 ~\anaconda3\envs\tf3\lib\site-packages\keras\backend\tensorflow_backend.py in pool2d(x, pool_size, strides, padding, data_format, pool_mode) 4070 x = tf.nn.max_pool(x, pool_size, strides, 4071 padding=padding, -> 4072 data_format=tf_data_format) 4073 elif pool_mode == 'avg': 4074 x = tf.nn.avg_pool(x, pool_size, strides, ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\ops\nn_ops.py in max_pool_v2(input, ksize, strides, padding, data_format, name) 3824 padding=padding, 3825 data_format=data_format, -> 3826 name=name) 3827 # pylint: enable=redefined-builtin 3828 ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py in max_pool(input, ksize, strides, padding, data_format, name) 5198 _, _, _op, _outputs = _op_def_library._apply_op_helper( 5199 "MaxPool", input=input, ksize=ksize, strides=strides, padding=padding, -> 5200 data_format=data_format, name=name) 5201 _result = _outputs[:] 5202 if _execute.must_record_gradient(): ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\op_def_library.py in _apply_op_helper(op_type_name, name, **keywords) 740 op = g._create_op_internal(op_type_name, inputs, dtypes=None, 741 name=scope, input_types=input_types, --> 742 attrs=attr_protos, op_def=op_def) 743 744 # `outputs` is returned as a separate return value so that the output ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\func_graph.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device) 593 return super(FuncGraph, self)._create_op_internal( # pylint: disable=protected-access 594 op_type, inputs, dtypes, input_types, name, attrs, op_def, --> 595 compute_device) 596 597 def capture(self, tensor, name=None, shape=None): ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\ops.py in _create_op_internal(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_device) 3320 input_types=input_types, 3321 original_op=self._default_original_op, -> 3322 op_def=op_def) 3323 self._create_op_helper(ret, compute_device=compute_device) 3324 return ret ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\ops.py in __init__(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def) 1784 op_def, inputs, node_def.attr) 1785 self._c_op = _create_c_op(self._graph, node_def, grouped_inputs, -> 1786 control_input_ops) 1787 name = compat.as_str(node_def.name) 1788 # pylint: enable=protected-access ~\anaconda3\envs\tf3\lib\site-packages\tensorflow_core\python\framework\ops.py in _create_c_op(graph, node_def, inputs, control_inputs) 1620 except errors.InvalidArgumentError as e: 1621 # Convert to ValueError for backwards compatibility. -> 1622 raise ValueError(str(e)) 1623 1624 return c_op ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_20/MaxPool' (op: 'MaxPool') with input shapes: [?,1,1,512].