Skip to content

Conversation

@clewis7
Copy link
Member

@clewis7 clewis7 commented Feb 17, 2025

WIP!

Started playing around with a simple CNN in pytorch to visualize the weights as the model is training using the MNIST dataset

image

The weights are definitely being updated every epoch, but the plot will not update until the last training epoch is done...not sure why

Another thing of note, pytorch tensors cannot directly be used with fpl right now because

File [~/repos/fastplotlib/fastplotlib/graphics/_features/_image.py:101](http://localhost:8888/lab/tree/examples/fastplotlib/graphics/_features/_image.py#line=100), in TextureArray._fix_data(self, data)
     95     raise ValueError(
     96         "image data must be 2D with or without an RGB(A) dimension, i.e. "
     97         "it must be of shape [rows, cols], [rows, cols, 3] or [rows, cols, 4]"
     98     )
    100 # let's just cast to float32 always
--> 101 return data.astype(np.float32)

AttributeError: 'Tensor' object has no attribute 'astype'

@kushalkolar
Copy link
Member

Are you trying to update a graphic in a for loop? You can't do this right now, see the discussions post. For now we can use zmq or see rendercanvas and try to expose the ondemand rendering mode in fpl

Torch tensors can't be used directly but if you do np.asarray it will not make a copy

@clewis7
Copy link
Member Author

clewis7 commented Feb 17, 2025

Torch tensors can't be used directly but if you do np.asarray it will not make a copy

Even when I do np.asarray I still get issues that the arrays are on different devices

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Are you trying to update a graphic in a for loop? You can't do this right now, see the discussions post. For now we can use zmq or see rendercanvas and try to expose the ondemand rendering mode in fpl

I was trying to use for loop, I will try using zmq for now

@kushalkolar
Copy link
Member

Yea you need to send to cpu

@clewis7
Copy link
Member Author

clewis7 commented Feb 17, 2025

Okay, still a bit messy and inelegant...but progress

Right now I have the weights updating after every training epoch

net_weights.mp4

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

Successfully merging this pull request may close these issues.

3 participants