unet icon indicating copy to clipboard operation
unet copied to clipboard

The program reported an error when I ran it on colab

Open hxhebit opened this issue 4 years ago • 11 comments

The Error is as follows. Using TensorFlow backend. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4479: The name tf.truncated_normal is deprecated. Please use tf.random.truncated_normal instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:148: The name tf.placeholder_with_default is deprecated. Please use tf.compat.v1.placeholder_with_default instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3733: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:2239: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

/content/drive/My Drive/unet/model.py:55: UserWarning: Update your Model call to the Keras 2 API: Model(inputs=Tensor("in..., outputs=Tensor("co...) model = Model(input = inputs, output = conv10) WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:793: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3657: The name tf.log is deprecated. Please use tf.math.log instead.

WARNING:tensorflow:From /tensorflow-1.15.0/python3.6/tensorflow_core/python/ops/nn_impl.py:183: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1033: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1020: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3005: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

Epoch 1/1 Found 0 images belonging to 1 classes. Found 0 images belonging to 1 classes. Traceback (most recent call last): File "/content/drive/My Drive/unet/main.py", line 18, in model.fit_generator(myGene,steps_per_epoch=300,epochs=1,callbacks=[model_checkpoint]) File "/usr/local/lib/python3.6/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/keras/engine/training.py", line 1658, in fit_generator initial_epoch=initial_epoch) File "/usr/local/lib/python3.6/dist-packages/keras/engine/training_generator.py", line 181, in fit_generator generator_output = next(output_generator) File "/usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py", line 733, in get six.reraise(*sys.exc_info()) File "/usr/local/lib/python3.6/dist-packages/six.py", line 693, in reraise raise value File "/usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py", line 702, in get inputs = future.get(timeout=30) File "/usr/lib/python3.6/multiprocessing/pool.py", line 644, in get raise self._value File "/usr/lib/python3.6/multiprocessing/pool.py", line 119, in worker result = (True, func(*args, **kwds)) File "/usr/local/lib/python3.6/dist-packages/keras/utils/data_utils.py", line 641, in next_sample return six.next(_SHARED_SEQUENCES[uid]) File "/content/drive/My Drive/unet/data.py", line 82, in trainGenerator img,mask = adjustData(img,mask,flag_multi_class,num_class) File "/content/drive/My Drive/unet/data.py", line 40, in adjustData elif(np.max(img) > 1): File "<array_function internals>", line 6, in amax File "/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py", line 2668, in amax keepdims=keepdims, initial=initial, where=where) File "/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py", line 90, in _wrapreduction return ufunc.reduce(obj, axis, dtype, out, **passkwargs) ValueError: zero-size array to reduction operation maximum which has no identity

Thank you for your answer

hxhebit avatar Mar 25 '20 12:03 hxhebit

I'm not sure but according to the error you've got its relating to the directory of your dataset: Epoch 1/1 Found 0 images belonging to 1 classes. Found 0 images belonging to 1 classes make sure if the directory of your dataset is correct

tamaraalshekhli avatar Mar 26 '20 06:03 tamaraalshekhli

I'm not sure but according to the error you've got its relating to the directory of your dataset: Epoch 1/1 Found 0 images belonging to 1 classes. Found 0 images belonging to 1 classes make sure if the directory of your dataset is correct

Thank u very much!

hxhebit avatar Mar 29 '20 09:03 hxhebit

how to test this model???

manvirvirk avatar Apr 05 '20 18:04 manvirvirk

#evalution loss_test,accuracy_test = model.evaluate(x_test,y_test) #You should change the x_test and the y_test.

print('\nloss_test',loss_test) print('accuracy_test',accuracy_test)

hxhebit avatar Apr 08 '20 06:04 hxhebit

thanks @djahdkjqbwfkb1213 . my predicted image is simply a grey box. Its not segmented image. Please help

manvirvirk avatar Apr 08 '20 08:04 manvirvirk

@manvirvirk try this pice of code as addition to original one , hope will help :

import cv2 import numpy as np

def saveResult(save_path,npyfile,flag_multi_class = False,num_class = 2): for i,item in enumerate(npyfile): if flag_multi_class: img = labelVisualize(num_class,COLOR_DICT,item)

    else:
        img=item[:,:,0]
        print(np.max(img),np.min(img))
        img[img>0.5]=1
        img[img<=0.5]=0
        print(np.max(img),np.min(img))
    io.imsave(os.path.join(save_path,"%d_predict.jpg"%i),img) 

tamaraalshekhli avatar Apr 08 '20 09:04 tamaraalshekhli

where to add this piece of code???

On Wed, Apr 8, 2020 at 3:26 PM tamaraalshekhli [email protected] wrote:

@manvirvirk https://github.com/manvirvirk try this pice of code as addition to original one , hope will help :

import cv2 import numpy as np

def saveResult(save_path,npyfile,flag_multi_class = False,num_class = 2): for i,item in enumerate(npyfile): if flag_multi_class: img = labelVisualize(num_class,COLOR_DICT,item)

else:
    img=item[:,:,0]
    print(np.max(img),np.min(img))
    img[img>0.5]=1
    img[img<=0.5]=0
    print(np.max(img),np.min(img))
io.imsave(os.path.join(save_path,"%d_predict.jpg"%i),img)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zhixuhao/unet/issues/173#issuecomment-610865910, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANAEAQDVRZPCHOBJ6YHRHELRLRC5PANCNFSM4LTNVTZQ .

manvirvirk avatar Apr 08 '20 10:04 manvirvirk

@tamaraalshekhli in which file we need to add this??

manvirvirk avatar Apr 08 '20 10:04 manvirvirk

just right after this part def labelVisualize(num_class,color_dict,img): img = img[:,:,0] if len(img.shape) == 3 else img img_out = np.zeros(img.shape + (3,)) for i in range(num_class): img_out[img == i,:] = color_dict[i] return img_out / 255

def saveResult(save_path,npyfile,flag_multi_class = False,num_class = 2): for i,item in enumerate(npyfile): img = labelVisualize(num_class,COLOR_DICT,item) if flag_multi_class else item[:,:,0] io.imsave(os.path.join(save_path,"%d_predict.png"%i),img) in data.py

tamaraalshekhli avatar Apr 08 '20 10:04 tamaraalshekhli

I really want to know how you solved this problem, thank you very much.

DreamOneYou avatar Jul 12 '20 02:07 DreamOneYou

I have compiled a list of frequently asked questions that I have encountered. You can find it here. Hope it helps!

Nelson-Gon avatar Jul 31 '20 16:07 Nelson-Gon