Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to work with a simple dataset that doesn't involve a .mat file? #3

Closed
Harsh9524 opened this issue Jul 25, 2020 · 3 comments
Closed

Comments

@Harsh9524
Copy link

I have a medical dataset of Lung X-Rays of Pneumonia patients and I want to apply this code on that dataset.
The dataset is in the following format.
Pneumonia/
----img1.jpg
----img2.jpg
Normal/
----img1.jpg
----img2.jpg

@changspencer
Copy link
Owner

You already have them in a picture form, so I would start with understanding the prepare_data method in kfold.py. It probably just needs some quick edits on being used for JPG images and depends on if you have a mask for it or not.

My memory is a little fuzzy, so if you still have questions about the code after looking for a while, let me know.

@Harsh9524
Copy link
Author

Hi @changspencer ,

Thank you for your response.
As per your suggestion I tried using my dataset directly. and since I have a preprocess.py file which outputs x_train.npy, y_train.npy, x_test.npy and y_test.npy I removed the prepare_data function from the kfold.py file and directly inputted my data in the form of numpy arrays. Since the prepare_data function was also returning numpy arrays.

After doing this and running the kfold.py file I encounter the following error. Can you please have a look at it?

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1864, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimensions must be equal, but are 3 and 2 for 'mask_1/mul' (op: 'Mul') with input shapes: [?,3,16], [?,2,1].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "kfold.py", line 278, in <module>
    main()
  File "kfold.py", line 273, in main
    num_folds, sep_conv, use_margin_loss)
  File "kfold.py", line 196, in k_fold_validation
    model = build_model(use_margin)
  File "kfold.py", line 91, in build_model
    masked_by_y = Mask()([capLayer2, y])
  File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/content/Tumor-CapsNet/capsulelayers.py", line 61, in call
    masked = K.batch_flatten(inputs * K.expand_dims(mask, -1))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py", line 884, in binary_op_wrapper
    return func(x, y, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_ops.py", line 1180, in _mul_dispatch
    return gen_math_ops.mul(x, y, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_math_ops.py", line 6490, in mul
    "Mul", x=x, y=y, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
    op_def=op_def)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 2027, in __init__
    control_input_ops)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1867, in _create_c_op
    raise ValueError(str(e))
ValueError: Dimensions must be equal, but are 3 and 2 for 'mask_1/mul' (op: 'Mul') with input shapes: [?,3,16], [?,2,1].

@Harsh9524
Copy link
Author

Harsh9524 commented Aug 12, 2020

@changspencer
UPDATE: I fixed the error by adjusting the layer 3. and changing the num_capsule from 3 to 2 since I have only two classes in my dataset.

CapsuleLayer(num_capsule=2, dim_capsule=16, routings=2,
                             name="ThirdLayer")(primaryCaps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants