ShahinSHH / COVID-CAPS

A Capsule Network-based framework for identification of COVID-19 cases from chest X-ray Images
49 stars 22 forks source link

When I try to run the code with a different dataset I get unwanted results. #3

Closed Harsh9524 closed 4 years ago

Harsh9524 commented 4 years ago
Using TensorFlow backend.
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/usr/local/lib/python3.6/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
tcmalloc: large alloc 1204224000 bytes == 0x57dc000 @  0x7fcf4464c1e7 0x7fcf421725e1 0x7fcf421db90d 0x7fcf421dc522 0x7fcf42273bce 0x50a7f5 0x50cfd6 0x507f24 0x509c50 0x50a64d 0x50cfd6 0x507f24 0x509c50 0x50a64d 0x50c1f4 0x507f24 0x50b053 0x634dd2 0x634e87 0x63863f 0x6391e1 0x4b0dc0 0x7fcf44249b97 0x5b26fa
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:74: 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:517: 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:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

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

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

2020-08-08 22:27:04.973016: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-08-08 22:27:04.975812: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200000000 Hz
2020-08-08 22:27:04.975982: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2594a00 executing computations on platform Host. Devices:
2020-08-08 22:27:04.976009: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2020-08-08 22:27:04.993713: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:1834: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

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

WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, None, None, 3)     0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, None, None, 64)    1792      
_________________________________________________________________
batch_normalization_1 (Batch (None, None, None, 64)    256       
_________________________________________________________________
conv2d_2 (Conv2D)            (None, None, None, 64)    36928     
_________________________________________________________________
average_pooling2d_1 (Average (None, None, None, 64)    0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, None, None, 128)   73856     
_________________________________________________________________
conv2d_4 (Conv2D)            (None, None, None, 128)   147584    
_________________________________________________________________
reshape_1 (Reshape)          (None, None, 128)         0         
_________________________________________________________________
capsule_1 (Capsule)          (None, 32, 8)             32768     
_________________________________________________________________
capsule_2 (Capsule)          (None, 32, 8)             2048      
_________________________________________________________________
capsule_3 (Capsule)          (None, 2, 16)             256       
_________________________________________________________________
lambda_1 (Lambda)            (None, 2)                 0         
=================================================================
Total params: 295,488
Trainable params: 295,360
Non-trainable params: 128
_________________________________________________________________
Not using data augmentation.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_grad.py:1250: add_dispatch_support.<locals>.wrapper (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
Train on 2000 samples, validate on 241 samples
Epoch 1/100
2020-08-08 22:27:07.765238: W tensorflow/core/framework/allocator.cc:107] Allocation of 201867264 exceeds 10% of system memory.
2020-08-08 22:27:07.967568: W tensorflow/core/framework/allocator.cc:107] Allocation of 201867264 exceeds 10% of system memory.
2020-08-08 22:27:07.967568: W tensorflow/core/framework/allocator.cc:107] Allocation of 201867264 exceeds 10% of system memory.
2020-08-08 22:27:08.485600: W tensorflow/core/framework/allocator.cc:107] Allocation of 198246400 exceeds 10% of system memory.
tcmalloc: large alloc 1784520704 bytes == 0x89d4c000 @  0x7fcf4464c1e7 0x7fcf2d855804 0x7fcf2fa61e34 0x7fcf3009ddbb 0x7fcf3009fb9c 0x7fcf300c57d1 0x7fcf300ca212 0x7fcf300cab11 0x7fcf2969ed94 0x7fcf29691050 0x7fcf2973c6d4 0x7fcf2973b544 0x7fcf42f2ea50 0x7fcf440106db 0x7fcf44349a3f
2020-08-08 22:27:10.457322: W tensorflow/core/framework/allocator.cc:107] Allocation of 184090624 exceeds 10% of system memory.
  16/2000 [..............................] - ETA: 25:53 - loss: nan - acc: 1.0000tcmalloc: large alloc 1784520704 bytes == 0x9e30c000 @  0x7fcf4464c1e7 0x7fcf2d855804 0x7fcf2fa61e34 0x7fcf3009ddbb 0x7fcf3009fb9c 0x7fcf300c57d1 0x7fcf300ca212 0x7fcf300cab11 0x7fcf2969ed94 0x7fcf29691050 0x7fcf2973c6d4 0x7fcf2973b544 0x7fcf42f2ea50 0x7fcf440106db 0x7fcf44349a3f
  32/2000 [..............................] - ETA: 23:56 - loss: nan - acc: 1.0000tcmalloc: large alloc 1784520704 bytes == 0x9db26000 @  0x7fcf4464c1e7 0x7fcf2d855804 0x7fcf2fa61e34 0x7fcf3009ddbb 0x7fcf3009fb9c 0x7fcf300c57d1 0x7fcf300ca212 0x7fcf300cab11 0x7fcf2969ed94 0x7fcf29691050 0x7fcf2973c6d4 0x7fcf2973b544 0x7fcf42f2ea50 0x7fcf440106db 0x7fcf44349a3f
  48/2000 [..............................] - ETA: 23:14 - loss: nan - acc: 1.0000tcmalloc: large alloc 1784520704 bytes == 0x97f98000 @  0x7fcf4464c1e7 0x7fcf2d855804 0x7fcf2fa61e34 0x7fcf3009ddbb 0x7fcf3009fb9c 0x7fcf300c57d1 0x7fcf300ca212 0x7fcf300cab11 0x7fcf2969ed94 0x7fcf29691050 0x7fcf2973c6d4 0x7fcf2973b544 0x7fcf42f2ea50 0x7fcf440106db 0x7fcf44349a3f
  64/2000 [..............................] - ETA: 22:48 - loss: nan - acc: 1.0000

Hey, Thank you for the amazing implementation of Capsule Network. I tried using the code with a different dataset containing COVID-19 CT samples. And in the starting only I get acc = 1.0000.

Can you help me up with this?

ShahinSHH commented 4 years ago

First of all, forget about warnings for now. You'll usually see lots of them when using with Tensorflow.

About your issue: This model is pre-trained on X-ray images so it can't produce reasonable results for CT scans. However, if you want to continue with this implementation, you can train your model from scratch completely based on CT scans but you should do the followings in the "binary.after.py":

  1. comment this line of code so the pre-training is discarded.
    • model.load_weights('pre-train.h5')
  2. Make sure that the size and dimension of your input are compatible with the model, otherwise you can change the input size in this line of code:
    • input_image = Input(shape=(None, None, 3)) Note that CT scan is a 3D data containing several 2D images (slices). This model can take only 2D images as an input so you have to feed it with 2D images (slices) only.
Harsh9524 commented 4 years ago

Thank you @ShahinSHH for your kind response.

I trained my dataset from scratch using the binary.py file and tried normalizing my CT Scan image dataset by using the data_augmentation() function in binary.py file and reduced the learning rate to 1e-4 while keeping the dataset untouched and it’s working now.

Best Regards, Harsh