ec-jrc / GHS-S2Net

Other
8 stars 5 forks source link

Error handling #5

Closed manapshymyr-OB closed 3 years ago

manapshymyr-OB commented 3 years ago

I clipped the image with size I have not changed any values for Image processing(all initial values are kept) and getting two errors: the first one:

(2779, 3286, 4)
0 1 2 3 Traceback (most recent call last):
  File "C:/Users/Gigabyte/PycharmProjects/GHS-S2Net/code/GHS_S2_run_prediction.py", line 109, in <module>
    Response = model.predict(T2, batch_size=batch_size*16, verbose = 0)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\keras\engine\training.py", line 1462, in predict
    callbacks=callbacks)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\keras\engine\training_arrays.py", line 324, in predict_loop
    batch_outs = f(ins_batch)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3740, in __call__
    outputs = self._graph_fn(*converted_inputs)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1081, in __call__
    return self._call_impl(args, kwargs)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1121, in _call_impl
    return self._call_flat(args, self.captured_inputs, cancellation_manager)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1224, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 511, in call
    ctx=ctx)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.ResourceExhaustedError:  OOM when allocating tensor with shape[800000,128,4,4] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
     [[node sequential_2_1/conv2d_5/convolution (defined at \Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
 [Op:__inference_keras_scratch_graph_7641]

the second one (I changed:

I2[I2>500] = 500

I2 = I2 / 500.

Batch size to 1000

):

Traceback (most recent call last):
  File "C:/Users/Gigabyte/PycharmProjects/GHS-S2Net/code/GHS_S2_run_prediction.py", line 109, in <module>
    Response = model.predict(T2, batch_size=batch_size*16, verbose = 0)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\keras\engine\training.py", line 1462, in predict
    callbacks=callbacks)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\keras\engine\training_arrays.py", line 324, in predict_loop
    batch_outs = f(ins_batch)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3740, in __call__
    outputs = self._graph_fn(*converted_inputs)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1081, in __call__
    return self._call_impl(args, kwargs)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1121, in _call_impl
    return self._call_flat(args, self.captured_inputs, cancellation_manager)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 1224, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\function.py", line 511, in call
    ctx=ctx)
  File "C:\Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.UnknownError:  Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
     [[node sequential_2_1/conv2d_5/convolution (defined at \Users\Gigabyte\PycharmProjects\pythonProject\DSP\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_keras_scratch_graph_7641]

Function call stack:
keras_scratch_graph

Can you please recommend some steps to handle these errors?

misterspook commented 3 years ago

Do not change this part of code, the training was done like this:

I2[I2>10000] = 10000
I2 = I2 / 10000.

Try with this batch size: Response = model.predict(T2, batch_size=256, verbose = 1)

manapshymyr-OB commented 3 years ago

@misterspook I have clipped a small area from S2_percentile_UTM_211-0000023296-0000000000.tif.

The clipped area has a smaller area and I am getting this error: `322786/322786 [==============================] - 4s 12us/step [[0.40370905 0.5965112 ] [0.17261449 0.8284869 ] [0.19422784 0.807319 ] ... [0.52428794 0.4777065 ] [0.48904425 0.5125672 ] [0.4869654 0.5142849 ]] (322786, 2) [[4037 5965] [1726 8284] [1942 8073] ... [5242 4777] [4890 5125] [4869 5142]] [ True True True ... True True True] [[4037 5965] [1726 8284] [1942 8073] ... [5242 4777] [4890 5125] [4869 5142]] (322786, 2)

ValueError Traceback (most recent call last)

in () 117 118 --> 119 Out = Response[:, 1].reshape(rows, cols) 120 121 #save the results ValueError: cannot reshape array of size 322786 into shape (10000,10000)`
misterspook commented 3 years ago

change the columns and rows variables to correspond to your actual array shape, they must be divisible with window size (5)

manapshymyr-OB commented 3 years ago

@misterspook thanks for the response. how should i calculate them based on the actual array shape? can you give an example?

misterspook commented 3 years ago

A.shape will return a tuple (m, n), where m is the number of rows, and n is the number of columns.

https://stackoverflow.com/questions/30898562/which-number-represents-rows-and-columns-in-the-tuple-returned-by-shape/30898622

manapshymyr-OB commented 3 years ago

A.shape will return a tuple (m, n), where m is the number of rows, and n is the number of columns.

https://stackoverflow.com/questions/30898562/which-number-represents-rows-and-columns-in-the-tuple-returned-by-shape/30898622

Can I have your e-mail for further questions?

manapshymyr-OB commented 3 years ago

@misterspook I am trying to run the script but it is stopping where reshape should be done. So I am trying:

model = load_model('/content/drive/MyDrive/GHS-S2Net/Pretrained_models/MODEL_CNN_31U.h5') #https://github.com/ec-jrc/GHS-S2Net/blob/main/Pretrained_models/MODEL_CNN_32T.h5
infile = '/content/drive/MyDrive/GHS-S2Net/OUTPUT.tif'

so OUTPUT.tiff (70 mb) file is clipped file from .tiff image which is downloaded from the https://data.jrc.ec.europa.eu/dataset/0bd1dfab-e311-4046-8911-c54a8750df79.

and the shape of the input image is after the ReadImage function equal to (4, 2779, 3286). Response = model.predict(T2, batch_size=256, verbose = 1) I tried with rows, cols = 10000, 10000 and with rows, cols = 3025, 3019

but I am getting still the reshaping errors: cannot reshape array of size 9131794 into shape (10000,10000) or cannot reshape array of size 9131794 into shape (3025,3019). If I write (4, 2779, 3286) then the size is not divisible by 5.