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

Installing under Anaconda #25

Open
sck-at-ucy opened this issue Jan 29, 2023 · 32 comments
Open

Installing under Anaconda #25

sck-at-ucy opened this issue Jan 29, 2023 · 32 comments

Comments

@sck-at-ucy
Copy link

I have been unable to get Manim_ml to properly install under Anaconda distribution. Any advise?

@helblazer811
Copy link
Owner

You ran pip install manim_ml and it didn't work?

@sck-at-ucy
Copy link
Author

It seemed to install OK. But when I try to run one of the examples, I get this error


ImportError Traceback (most recent call last)
Cell In[2], line 3
1 from manim import *
----> 3 from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork
5 # This changes the resolution of our rendered videos
6 config.pixel_height = 700

ImportError: cannot import name 'Convolutional2DLayer' from 'manim_ml.neural_network' (/usr/local/anaconda3/envs/my-manim-environment/lib/python3.8/site-packages/manim_ml/neural_network/init.py)

@sck-at-ucy
Copy link
Author

Wonder if it is a path issue?

@helblazer811
Copy link
Owner

helblazer811 commented Jan 29, 2023

Hmmm. I tried to simplify imports by having everything importable from manim_ml.neural_network. There may be a bug in how that is done.

Can you try and do from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer?

Does that fix the issue?

@helblazer811
Copy link
Owner

helblazer811 commented Jan 29, 2023

Also can you specify which version of manim_ml you have installed? You can do this by running pip show manim_ml.

@sck-at-ucy
Copy link
Author

I made the change and was able to import

@sck-at-ucy
Copy link
Author

Name: manim-ml
Version: 0.0.13
Summary: Machine Learning Animations in python using Manim.
Home-page: https://github.com/helblazer811/ManimMachineLearning
Author: Alec Helbling
Author-email:
License:
Location: /usr/local/anaconda3/envs/tf/lib/python3.10/site-packages
Requires:
Required-by:
Note: you may need to restart the kernel to use updated packages.

@sck-at-ucy
Copy link
Author

I should mention that I am trying all these inside a Jupyter notebook

@helblazer811
Copy link
Owner

I made the change and was able to import

Awesome. I'll look into the importing issue. Thanks for the help!

@helblazer811
Copy link
Owner

I should mention that I am trying all these inside a Jupyter notebook

I have not tested this at all in Jupyter notebook environments. So it may not work there. However, it looks like the core ManimCommunity library did work to support Jupyter.

https://docs.manim.community/en/stable/installation/jupyter.html

@sck-at-ucy
Copy link
Author

Yes, I am able to run all the standard examples for ManimCommunity from inside Jupyter notebooks.

Thank you, let me know if you want me to do any further tests.

@helblazer811
Copy link
Owner

Amazing! Feel free to go through more of the examples in the examples/ directory. I didn't expect all of the attention so I haven't tested everything as thoroughly as I should have.

@sck-at-ucy
Copy link
Author

OK, I sort of got it working in Jupyter. I think something is broken with a path (at least on my installation) but the two things I did that got it work are:

  1. Changed this part in example code because it was complaining about Neural_Network()
# The code for generating our scene goes here
    def construct(self):
        # Make the neural network
        nn = NeuralNetwork([.     # <------------------------------------Changed here!
                Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
                Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
                Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
                FeedForwardLayer(3),
                FeedForwardLayer(3),
            ],
            layer_spacing=0.25,
        )
  1. Before running the example, in the previous code cell of Jupyter I simply run
# %load '/usr/local/anaconda3/envs/my-manim-environment/lib/python3.8/site-packages/manim_ml/neural_network/neural_network.py'
![jupyter_manim](https://user-images.githubusercontent.com/5185237/215352183-d4112a05-0057-41a9-8f45-79ccaba0d068.png)

The second step tells me that somehow the pip installation probably did not properly set the path.

@helblazer811
Copy link
Owner

In the code, what exactly did you change?

I am not sure if you issue is specific to jupyter. I wonder if you could copy the example code at the top of the Readme into a file called example.py and try running manim -pql example.py in your command line inside of the same conda environment.

@sck-at-ucy
Copy link
Author

This is the cell that runs successful (after loading manually the lib in the previous cell)

%%manim -pql -v WARNING BasicScene

#from manim_ml.neural_network import neural_network

#from manim_ml.neural_network.layers.convolutional_2d import Convolutional2DLayer

#from manim_ml.neural_network.layers.feed_forward import FeedForwardLayer


# This changes the resolution of our rendered videos
config.pixel_height = 700
config.pixel_width = 1900
config.frame_height = 7.0
config.frame_width = 7.0

# Here we define our basic scene
class BasicScene(ThreeDScene):

    # The code for generating our scene goes here
    def construct(self):
        # Make the neural network
        nn = NeuralNetwork([        #<------------------------------ Changed the name from Neural_Network
                Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
                Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
                Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
                FeedForwardLayer(3),
                FeedForwardLayer(3),
            ],
            layer_spacing=0.25,
        )
        # Center the neural network
        nn.move_to(ORIGIN)
        self.add(nn)
        # Make a forward pass animation
        forward_pass = nn.make_forward_pass_animation()
        # Play animation
        self.play(forward_pass)

@helblazer811
Copy link
Owner

So the name of the object is NeuralNetwork not Neural_Network. I looked through the readme and it doesn't look like that was accidentally written anywhere.

What did you do to manually load the library in the previous cell?

Again, thanks so much for all of the help!

@sck-at-ucy
Copy link
Author

Just run this command. It loads the file and then I execute the cell.

%load '/usr/local/anaconda3/envs/my-manim-environment/lib/python3.8/site-packages/manim_ml/neural_network/neural_network.py'
![jupyter_manim](https://user-images.githubusercontent.com/5185237/215352183-d4112a05-0057-41a9-8f45-79ccaba0d068.png)

@helblazer811
Copy link
Owner

Ok. I am unsure if this is a jupyter-specific issue. I will try testing it out in a jupyter notebook.

@sck-at-ucy
Copy link
Author

Great, thank you!

@helblazer811
Copy link
Owner

I think I just forgot to add the manim_ml/neural_network/__init__.py file which defined all of these import shortcuts in the most recent pypi package. It should be good now if you install again.

@sck-at-ucy
Copy link
Author

It solved half of the problem in the sense that now I can use

from manim_ml.neural_network import neural_network, Convolutional2DLayer, FeedForwardLayer

to import the layers. However, I am still not able to avoid having to load manually the library, so the path issue continues.

@helblazer811
Copy link
Owner

Hmmm. Is it possible that you are not running the Jupyter notebook with the conda environment's kernel?

@sck-at-ucy
Copy link
Author

I take it back. I restarted the kernel and go it to work like this

First cell:

from manim import *

Second cell:

%%manim -pql -v WARNING BasicScene
from manim import *

from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork

# This changes the resolution of our rendered videos
config.pixel_height = 700
config.pixel_width = 1900
config.frame_height = 7.0
config.frame_width = 7.0

# Here we define our basic scene
class BasicScene(ThreeDScene):

    # The code for generating our scene goes here
    def construct(self):
        # Make the neural network
        nn = NeuralNetwork([
                Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
                Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
                Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
                FeedForwardLayer(3),
                FeedForwardLayer(3),
            ],
            layer_spacing=0.25,
        )
        # Center the neural network
        nn.move_to(ORIGIN)
        self.add(nn)
        # Make a forward pass animation
        forward_pass = nn.make_forward_pass_animation()
        # Play animation
        self.play(forward_pass)

@sck-at-ucy
Copy link
Author

By the way, I have a suggestion for future additions. It would be nice if it could include additional type of layers as used in Keras, such as Max_Pooling2D, Concatenate and Up_Sampling. That would be super!

@helblazer811
Copy link
Owner

I take it back. I restarted the kernel and go it to work like this

First cell:

from manim import *

Second cell:

%%manim -pql -v WARNING BasicScene
from manim import *

from manim_ml.neural_network import Convolutional2DLayer, FeedForwardLayer, NeuralNetwork

# This changes the resolution of our rendered videos
config.pixel_height = 700
config.pixel_width = 1900
config.frame_height = 7.0
config.frame_width = 7.0

# Here we define our basic scene
class BasicScene(ThreeDScene):

    # The code for generating our scene goes here
    def construct(self):
        # Make the neural network
        nn = NeuralNetwork([
                Convolutional2DLayer(1, 7, 3, filter_spacing=0.32),
                Convolutional2DLayer(3, 5, 3, filter_spacing=0.32),
                Convolutional2DLayer(5, 3, 3, filter_spacing=0.18),
                FeedForwardLayer(3),
                FeedForwardLayer(3),
            ],
            layer_spacing=0.25,
        )
        # Center the neural network
        nn.move_to(ORIGIN)
        self.add(nn)
        # Make a forward pass animation
        forward_pass = nn.make_forward_pass_animation()
        # Play animation
        self.play(forward_pass)

Amazing!

@helblazer811
Copy link
Owner

By the way, I have a suggestion for future additions. It would be nice if it could include the additional type of layers as used in Keras, such as Max_Pooling2D, Concatenate and Up_Sampling. That would be super!

Great ideas. I already have implemented Max_Pooling2D. You can check it out in one of the readme examples.

https://github.com/helblazer811/ManimML/blob/main/Readme.md#:~:text=Max-,Pooling,-A%20common%20operation

@sck-at-ucy
Copy link
Author

Oh, that's becoming really nice!

@sck-at-ucy
Copy link
Author

By the way, is padding something to be accounted for?

@helblazer811
Copy link
Owner

helblazer811 commented Jan 30, 2023 via email

@sck-at-ucy
Copy link
Author

Perfect

@helblazer811
Copy link
Owner

I added padding. For some reason I can't upload the video, but you can see it here: https://twitter.com/alec_helbling/status/1620641566024171520?s=20.

@sck-at-ucy
Copy link
Author

sck-at-ucy commented Feb 1, 2023 via email

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