capsnet | Reimplementation of Capsule net from https | Machine Learning library
kandi X-RAY | capsnet Summary
kandi X-RAY | capsnet Summary
Reimplementation of Capsule net from For more information on the implementation, see my blog post.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Builds the caps net
- Uses DigitCaps
- Resolve primary caps
- Construct a decoder for decoder
- Computes caps loss
- Constructs the decoder network
- Squash s_j
- Compute accuracy
- Wrapper around capsule prediction
- Returns the loss of the reconstruction loss
- Evaluate accuracy on a given epoch
capsnet Key Features
capsnet Examples and Code Snippets
Community Discussions
Trending Discussions on capsnet
QUESTION
I'm working on CapsNet from here , which is implemented on the MNIST dataset with 10 digits, but I've changed the code to work with a dataset with three classes. Model training and testing work fine, but the manipulate latent function causes an error:
...ANSWER
Answered 2021-Mar-16 at 09:14This is because you're using sum()
instead of len()
.
QUESTION
I have a dataset with more than 4000 images and 3 classes, and I'm reusing a code for capsule neural network with 10 classes but I modified it to 3 classes, when I'm running the model the following error occurs at the last point of the first epoch (44/45):
...ANSWER
Answered 2021-Mar-13 at 12:25Try make the X set so that the batch size perfectly fits the data i think the batch size remainder is 15 after fitting to all the data
For eg : make it a multiple of 100
QUESTION
I am learning capsnet now, and trying to transfer the code from local computer to colab. The code runs well on my local computer, but raise an error when I try it on colab. ValueError: Inconsistent shapes: saw (1152, 10, 1, 10, 16) but expected (1152, 10, 1, 16).
When I try other matching like [3,1], I will get the following error. In this case, x's dimension backs to 4 and x[3] == y[2]. ValueError: Can not do batch_dot on inputs with shapes (1152, 10, 1, 8) and (1152, 10, 8, 16) with axes=[3, 1]. x.shape[3] != y.shape[1] (8 != 10).
I locate the reason of this error on the function tf.scan. And I installed tensorflow 1.13 on my computer. But I don't know how to fix it. Please help me.
Here is the code.
...ANSWER
Answered 2020-Jan-07 at 16:36Finally, I solved it.
Function tf.scan()
here does nothing wrong, but does not accord to my environment. The purpose of tf.scan()
here is similar to the fully connected layer.
According to the definition of fully connected layer, we just need to alter the function, but don't use tf.map_fn()
, since that we'll get the same error.
And try this one. This function helps a lot to solve this problem.
QUESTION
It worked fine when I used fit, but when I used fit_generator, I got a problem.
I used the call back method to find the confusion matrix at the end of each train epoch.
However, the accuracy obtained from the confusion matrix and the validation accuracy output from keras differ.
My code is below.
...ANSWER
Answered 2019-Apr-10 at 12:41I solved this problem using sequence instead of generator.
I can find out why this phenomenon occurs in the following sources.
https://github.com/keras-team/keras/issues/11878
A simple example using sequence is shown below.
https://medium.com/datadriveninvestor/keras-training-on-large-datasets-3e9d9dbc09d4
QUESTION
I am training a Capsule Network with both encoder and decoder part. It works perfectly fine with all the classes (10 classes) of the MNIST data set. But when I am extracting a single class say (class 0 or class 5) and then training the capsule network, the reconstruction of the image is very poor.
Where do I need to change the network setting, or do I have an error in my data preparation?
I tried:
- I changed the total class from 10 (for ten digits to 1 for 1 digit and even for 2 for 2 digits).
- When I am using the default MNIST dataset, I am getting no error or tensor size, but when I am extracting a particular class and then passing it into the network, I am facing issues like a) Dimensional Issues b) Float tensor warning.
I fixed these things but manually adding a dimension and converting the data to data.float().cuda() tensor. I did this for both the case i.e when I am using the 10 Digit Capsules and when I am using the 1 Digit Capsules for training a single class digit.
But after this, the network is running fine, but I am getting really blurred and poor reconstructions. While when I am training the whole MNIST dataset without extracting any class and passing it to the network, it doesn't throw any error and the reconstruction works really fine.
I would love to share the more detail and other parts of the code -
...ANSWER
Answered 2019-Jan-18 at 16:08I checked the normal performing code and then the problematic one, I found that the dataset passed into the network was of not same nature. The problems were -
- The MNIST data extracted for a single class was not transformed into tensor and no normalization was applied, although I tried passing it through the transformation.
This is what I did to fix it -
I created transformation objections and tensor objection and then passed by list comprehension elements to it. Below are the codes and the final output of my network -
Preparing class 0 dataset (dataset for the digit 5)class Mnist: trans = transforms.ToTensor() normalize = transforms.Normalize((0.1307,), (0.3081,)) def init(self,batch_size):
QUESTION
I'm new in Tensorflow and Keras. I trying to run code in Keras. I have labels that convert to one hot encoding whit 2 depth and after that convert it to Keras layers format. now when I rum my code I got this error:
Traceback (most recent call last): File "/Users/vahid/Documents/Thesis/Code/new_code/CapsNet_model.py", line 224, in CapsNet((None,28,28,1),2,3,trainImg,trainLbl) File "/Users/vahid/Documents/Thesis/Code/new_code/CapsNet_model.py", line 164, in CapsNet x_recon = k.layers.Dense(512, activation='relu')(masked) File "/Users/vahid/TensorProject/lib/python3.6/site-packages/keras/engine/base_layer.py", line 443, in call previous_mask = _collect_previous_mask(inputs) File "/Users/vahid/TensorProject/lib/python3.6/site-packages/keras/engine/base_layer.py", line 1311, in _collect_previous_mask mask = node.output_masks[tensor_index] AttributeError: 'Node' object has no attribute 'output_masks'
and the part of the code that I run and got error:
...ANSWER
Answered 2018-Dec-01 at 09:43well, I find out how to fix this problem. actually, we can use two kinds of Keras in our code. Keras package or just use tf.keras. In this code I using Keras package when using "Dense". for example in x_recon = k.layers.Dense(512, activation='relu')(masked)
so it seems that tf.keras and Keras have different source and when I've changed k.layers
to tf.keras
problem was fixed.
QUESTION
I was looking at this capsnet code on github
And I can't find what does the line no. 116 mean?
...ANSWER
Answered 2017-Dec-27 at 05:42From Keras model functional API: https://keras.io/models/model/
See Method > compile > metrics
metrics: List of metrics to be evaluated by the model during training and testing. Typically you will use
metrics=['accuracy']
. To specify different metrics for different outputs of a multi-output model, you could also pass a dictionary, such asmetrics={'output_a': 'accuracy'}
.
(source: https://github.com/keras-team/keras/blob/master/keras/models.py#L786-L791)
What Does it Do?The line outputs the layer called capsnet
(which can be found within the same file) with accuracy
metric. The rest is just the same as the document you provided.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install capsnet
You can use capsnet like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page