Instead, if you say, OK, the way I'm optimizing this is inside the prediction function, then you can literally compute the computation graph and optimize it.


Noether Networks: Meta-Learning Useful Conserved Quantities (w/ the authors)

So that's the reason why we do that at runtime. OK, second point in your question was why theta and not X?


And that's a great question as well. On that, we experimentally found it very impactful,


like very stark difference between both options in the previous in the tailoring paper.


And we have a we think we understand why the intuition is optimizing X actually helps experimentally.


It makes sense that it helps, and it also empirically found that it helps, but it helps very little.


The reason being that you can it may find like an adversarial example on that optimizes G perfectly and makes G very happy with very small changes.


If you optimize theta instead, theta has kind of the geometry of the task.


It knows the ways that it the ways to change the output condition on the input that kind of still do not deviate too much from what it has learned.


So theta captures the dynamics and says, OK, I probably got it a bit wrong because I'm not conserving G.


So but but I don't want to deviate too much from what I've learned.


So optimizing theta still make sure that you satisfied what you've learned so far.


And then it leads to much, much larger improvements.


I mean, it does bring up like just right now, it does.


It does seem like might be possible to to set up some adversarial setting right here where you could maybe use G as sort of a discriminator,


not optimizing X directly, but sort of optimizing the parameters of F in maybe more of an adversarial setting.


So not directly taking a gradient step with respect to the loss, but maybe saying, you know, is the is according to what G outputs.


Is this a real sample or is it a sample that I have predicted? Is this anything on your radar?


Yeah, yeah, I think it's I think there's something like what you said that that that going to be there in particular.


I think G has a feeling like like this adversarial discriminator because it's telling you, oh, if you're not satisfying G conservation,


then most likely you are wrong, especially if you don't satisfy it by a large amount because they're they're approximately conserved.


So that's one. So one thing I'm interested in going forward and I think that that could be a avenue of many future works is that we focused a lot on when we were trying to make predictions on kind of generative


networks, the fact that you're sorry, generative, not in the sense of self-supervised learning, but more in like you predict the next input given the sorry, the output given the input.


You have to generate the thing. G is like a checking network and checking sometimes is easier, right?


You just have to say stand back and say, OK, I like it. I don't like it. And that may be much easier to do.


And also the type of network that you have that you build in may be very different architecturally, maybe the type of networks that we want to encode and construct may be architecturally different from the F networks.


And maybe combining these proposal networks with these checking networks may make different architecture classes that could be useful.


Yeah, I wanted to get a little bit more into so you have you have experimental results where you compare to various baselines like, you know, without and obviously, obviously you're better than them, which is what we've come to expect from machine learning papers.


I want to I want to focus a little bit on also here you have an investigation into what the conservation, what the embedding network, this G network actually looks at.


Do you maybe want to comment on this a little bit and why this makes you a little like why this makes you comfortable, say, like comparing this to conserving quantities and and why your assumptions might be correct?


Yeah, yeah. So we were able to check the fact that we were learning conserved quantities in two ways. One, the symbolic experiments on the physics based, we were able to recover energies.


But in the video, it's very hard to know, are you learning anything meaningful? And so we were able, OK, let's let's inspect what the G network is looking at.


One thing here, just to be precise, is that we have to it's a dynamical system, so we have to have some notion of velocity. So G was actually taking two consecutive frames to be able to have any chance of visualizing the velocity.


But here, OK, we only look at one of the frames and we say, OK, where is it looking at? And if it's not looking at reasonable stuff, then maybe it's not doing anything.


And so if you look at the another loss, it's an emissive of of multiple dimensions. In our case, we tried that type of parameter didn't really matter for experimentally.


We'll come back to this a bit later. But let's say we fixed it to 64. So it was pretty good. Sixty four numbers.


But you can if you think about it, you can kind of rotate and exchange the dimensions and whatnot.


So really what matters only is the PCA of this. So you can take the PCA and look at what's the most important dimensions and then and then kind of the list important.


And we found that even though we were trying to conserve 64 different numbers, in practice, they were like only four to six that mattered.


And in particular, the first one mattered a lot, like 84 percent of the variance was captured by the first dimension.


So it's the one on the left. And it was comforting to see that this dimension was looking at the right stuff.


So in particular, it looks primarily at the object that's falling down.


You can see it in red. And then we also saw that it was often looking at the edge.


We think that this is because there were two types of here.


They're both right to left, but there were sometimes sequences that the object was falling left to right.


So we think that the edge of the ramp was a good signal on measuring this.


And it also looks very faintly, but it also looks at a bit of the object waiting to be hit.


So that was very comforting to see. So you can see, for instance, other dimensions that were much less important than the first one.


They are not very meaningful at all. And then the fourth one and the sixth one do have some meaning.


We think that the fourth one was caring more about orange type stuff.


And we think that maybe it's because of there was sometimes a hand that was going on there.


We don't know. And the sixth one, we found that it was following blue objects very closely.


So here, of course, we only show one example over time.


So this is a time sequence as we track the object on the appendix.


We show that it basically didn't matter. The example didn't matter.


It reproduced very nicely. And that also gave us confidence that the G network was learning something meaningful.


Cool. So I have this question. You have a lot of these physics examples, right?


Which also comes close to your notion of, you know, in physical systems, in dynamical systems, there are these conserved quantities and so on.


Is it fair to say that probably in most video prediction tasks, unless it's like, I don't know, a SpongeBob video where every four seconds there is a cut,


like in most video prediction tasks, I can reasonably say if a model just observes the pixel information,


then probably it's going to find some of these conserved things.


It's almost like a prior on, you know, stuff over time moves slowly and in according to physical reality or something like this.


Yeah, yeah, exactly. I think there's probably some type of prior like this that enforcing the fact that some things are approximately conserved is going to be useful beyond physics.


It's true that because of the motivation, especially, we thought that that's the most likely thing to work.


And also the message was clear. But we think that possibly in other types of videos, like, well, even like many videos are essentially everything is physics.


If you're in the real world, like cars or people moving around. But they also have some intrinsic movement that doesn't follow passive physics laws.


Do you have something in mind, like except cuts between scenes?


Yeah, cuts you'll get goodbye.


Do you have anything other? Is there like a prominent example where this type of model would fail?


Fail. So I think.


I mean, I was thinking maybe.


Yes, I know.


Go ahead.


One easy example of something that would fail is you have a video and you often have things that enter the video that were not in the video.


Yeah.


Then here you get into trouble because there's something that was not observed. It's the same thing that we were talking energy dissipation before.


If you consider the entire system, then maybe there's something that's going to get conserved if you consider heat and whatnot.


But anything that you cannot observe then forces some things that are not getting conserved.


So extra objects that appear and disappear, then you're going to get into trouble.


Yeah, I was thinking I was like going to mention the exact same thing.


And I mean, it's still going to be the case that the G network, you know, it can it can just output something like, well, the energy of the entire universe is still the same.


Right. But that then ceases to be useful.


Yes. Yes, exactly. So, yeah, things. And one other thing, I think conversely, it could be that there's a lot of work that will need to be done if the camera is is moving a lot.


Because then all of these objects will for sure appear that were not there because you're looking at stuff that was not there.


So if you look at the videos, this video is a static, the camera is static. Sorry, the scene is not static.


So most likely some work will need to be done in this case.


One good thing about this is that we're not fully imposing the conservation.


So some approximately, actually, the fact that it's approximate allows us to handle things that were not previously possible before. But still, you will get into trouble if you keep entering stuff.


But it's I mean, just just out of intuition, it seems more likely that the network detects something like, you know, there's there's a blue bunch of pixels and and an orange bunch of pixels.


And these pixels sort of move together as objects rather than the network from video somehow determining, aha, there's laws of physics and there's gravity and there's friction and they're sliding.


The first situation seems a bit more likely here. Right. Yes. Yes. Actually.


So just to give a bit of context of how we came up with this idea.


Initially, the original tailoring paper, we initially came up with applications on adversarial examples and contrastive learning.


And we had the feeling that we could be applied to inductive devices, but I was not fully sure.


I didn't know exactly how. And then the Rusted Ray gave a talk at MIT.


It's online on the YouTube seminar. And it was telling us how it's very hard to encode inductive devices in neural networks.


And in their case, basically, they were predicting how a robot was pushing a bunch of carrot and the carrot was moving around and they trained it between the carrot predictor and that it worked fine.


Very good prediction. But then they used it for planning a test time. And suddenly it was not conserving care.


It was making care disappear instead of bringing it to the proper place.


And that and they were like, OK, that neural network don't work.


So we're going to use a constraint linear model and they were going to solve the problem this way. But I was like, OK, maybe maybe we can actually if we enforced it inside the prediction function, it would conserve care.


And and then that was the motivation that told it like, let us go into this direction.


Cool. Is there anything else you want to say about the the experimental results we touched on sort of upping the inner steps and the and the grad chem?


But is there anything special you want to say about sort of your tests on, for example, the pendulums or?


Yeah, I think some of the experiments depends on how much time we have. But on the pendulum, there was a symbolic component.


So the G doesn't have to be fully neural. Yeah. So in the origin, in the first I think those are the first experiment, the G is kind of a program with some parameter like a formula.


And there we search over formulas because it's a state information that you draw, like the angle and the momentum.


And there we search over formulas. And then there are some parameters as well that get trained over with gradient descent.


And there we saw that, OK, we we are able to recover the true formulas of the energy and it leads to better prediction than a vanilla MLP that does not learn about conservations.


And there also you can see that that actually you can you can even handle these approximate constraints where you have real data, which then the networks that have the hard coded constraints can't handle as well.


Yeah, exactly. So there is a cool paper, Hamiltonian Neural Networks that encodes I think the graph is a bit above, I think that basically the here what this one.


Perfect. So it's a very cool paper that they construct the network in such a way that it conserves energy.


And so we thought it was a very good comparison because it improves a lot the above vanilla MLP that does not conserve energy.


So if you look on the right, this is changing agent and conserve quantity, which is what they believe is the predict it's going to be some of the energy.


You can see the baseline neural network, which is just the D.F. basically just F quickly loses energy.


And therefore, this is going to lead to much worse predictions on the left. You can see the MSE goes up.


If you fully impose energy, well, this is a much better inductive bias.


The fact that energy is conserved and you can see that the predictions are much better.


But if you only softly encode it, then we show that we can do much better.


And then we compare to actually knowing the loss, the formula for the energy.


And we see that essentially the performance is pretty much the same.


We are able to discover it and then use it to softly encode energy conservation.


Nice. Seems like seems like a good deal.


I mean, it's really cool that if you know something about your problem, this is sort of another way that you can directly encode that even in sort of a soft way.


I think this the softness is something super useful, especially in the real world, right?


Compared to sort of the really hard constraints that often these asymmetry conserving neural networks have.


Yeah. Yeah. Cool. Yeah. I think this is about it for this paper. Is there anything you want to you have a theoretical section?


We didn't talk much about the symbolic regression, but I think we've gotten sort of to the essence.


Is there anything else you want to add to this or or anything people should know that your code is online?


Yeah, the code is online. So it can be a bit of one. It's on with PyTorch.


But I think actually JAGS will make it these type of things of parameter, a kind of this tailoring process that essentially you have a parameter per example with JAGS are very it's very, very easy to encode and parallelize.


So that will also make it easier. But with PyTorch, it's already pretty easy to the with PyTorch higher.


It's very easy to implement. So I think that should be easy to build up.


I just wanted to point out that this was a group effort.


So in particular, Dylan Doblar was also first co-first author in this work and did a lot of the experiments.


And then we also had Alan Cho and Chelsea Finn from Stanford collaborating on this work because we found they had a really cool paper on learning discrete symmetries, meta learning symmetries by reparameterization.


And then we also had Professor Josh Stellenbaum from MIT Cognitive Science and Kenji Kawaguchi from the University of Singapore.


Cool. Excellent. Well, Ferran, thank you so much for being here with us today. And all the best. I hope you have great, great ideas in the future.


NeuralHash is BROKEN - How to evade Apple's detection & craft hash collisions (w/ Open Source Code)

So, I've made multiple videos about this already.


ML News reported, Apple is releasing their new system to detect child abuse material,


which includes running code on the device of the actual users before they upload images


to iCloud.


I've also made a video about the technical summary that Apple released, where they detail


how they're going to preserve user privacy in the face of all of this.


And the system is pretty smart, but in that video, I already pointed out while the cryptographic


and security part of the system is smart and fulfills all the privacy requirements of what


Apple claims, the neural network part is the weak part right here.


But also in that video, I outlined two weak points of the system.


The first weak point is who controls the database, who does the manual checking and so on.


This is politics, I guess the second part is the neural network part.


At the beginning of this whole pipeline, there is a neural network that is trained to recognize


when two images are the same.


So the neural network is supposed to be robust to some transformations.


For example, if you resize the image, if you re encode the image, and so on, the bits of


the image will change.


However, the neural network should still recognize that that is the same image.


And you can definitely train neural networks to do that.


However, criticism has come up.


And I've mentioned this as well, that neural networks being neural networks, they can be


tampered with with so called adversarial attacks.


Now, it didn't even take a week before code was released to find the model that Apple


is using on device, it was actually on my computer the whole time and convert that to


a format that we can work with in neural network frameworks.


So we already have the first reports of a forced collision.


That means two images that look essentially nothing alike yet the network thinks that


is the same image.


So this can be potentially used to frame someone ie send them images that are seemingly innocuous,


yet the images are perturbed in just the right way to make Apple think they're the same as


one of the images in their database.


On the other hand, using the same techniques called adversarial attacks, we can also evade


this system, meaning that we can change this neural hash of any image pretty much as we


please.


So I thought, hey, why not give it a try.


So this is partially based on code that's already available.


And I'll link to that.


I'll make my code available that has references to that code that I'm basing my work on.


So I'm going to show you how to force a collision.


If you understand how to force a collision, it's pretty easy to also understand how you


can evade a collision.


So that exercise is left to the reader, forcing a collision is actually the more difficult


part.


So that's what I'm going to show you today.


And this is doable by anyone with introductory skills to deep learning programming.


Alright, so first, we're going to need some sort of a image that we want to perturb.


Let's take this image right here of nice doggy.


Hey, Shiba Inu.


And let's assume that we are in possession of an image that we know is in the database


of bad material.


Pretend for a second that this image of the Titanic is that image that is in the database.


Alright, so I've already used the code available online to convert the model into the ONNX


format, which is an interchangeable format for the different frameworks of deep learning.


And then I further converted it to a TensorFlow format, which is one of the major frameworks


for deep learning.


Now with a little bit of plumbing, I can then further shove this into a library called the


adversarial robustness toolbox, which is used to do research on adversarial examples.


So our plan is going to be essentially, we have the source image.


And if we just run that through the neural pipeline, it will give us some neural hash


at the end, that neural hash is computed from the network's output, which is some vector


in high dimensional space.


If we run the target image through the same neural network, we'll get a different vector.


And because of that, we'll get a different neural hash.


Now what we can do with an adversarial attack is we can compute the minimal perturbation


necessary to the source image.


And that's really going to be a tiny perturbation, you can't see it with the naked eye.


But this tiny perturbation, if we do it in the right way, causes the output to change


all the way to align with the output vector of the target image.


And if we align the two vectors closely enough, then they will output the same neural hash,


they will fall into the same bucket of the LSH algorithm.


And they will give the same output.


I've explained in the last video already what LSH is and how that works.


So if you want to find more about that, check it out.


So when I recorded this, I was a bit overeager in what I could do, though, I'm pretty sure


with some engineering, this can be smoothed out.


But you see the image on the left is the one we started with.


And our target image is this image of the Titanic.


And the image on the bottom is the collision image.


So it's noticeably different.


So first of all, the resizing, that's just the fact of the algorithm that doesn't matter,


actually, but you can clearly see there are some artifacts in the image.


However, you would still notice it as being very similar to the original image, yet it


is in the same bucket.


So it has the same neural hash as the Titanic image, which you know, that's pretty astonishing.


Alright, so as you can see, the code for this is relatively minimal.


And we don't have to run this for long until we actually find a collision.


And the image that we craft looks like this.


Remember, this has the same neural hash as the Titanic image.


So on Apple side, at least before the manual review, this shows up as being flagged to


be the same as this Titanic image, it should be plainly obvious, you know how you can frame


people if you see these things.


Now, if you get this crafted image, you don't think twice that this could be some kind of


a mal intended essentially a virus.


And as soon as you upload it to iCloud in Apple's headquarters, a red light flashes


next to your name.


Now hold on, you might say in order to pull off this attack, you do actually need this


Titanic ish image, right?


Therefore, you must already be in pretty shady waters because the possession of this image


presumably is illegal already.


And I'm here to tell you not necessarily see since we now have another image that you know,


is not an illegal image, it's not the same image to a human.


But nevertheless, that image is in fact, in this bucket, we now are in possession of a


completely legal image from the illegal bucket.


So in the future, we can simply use that image as the target image.


So technically, only one person at the very beginning has to have access to some kind


of illegal material.


And they can simply pass on the non robust features that we all adjust to.


And subsequently, nobody is doing anything illegal.


Yet we're able to essentially DDoS Apple with this, there you go, we've just beaten the


most valuable company on the planet with ironically, a laptop that they manufactured in less than


a few minutes.


Now what does it matter you ask?


Well, I think this is pretty worrisome.


So there's a system that's implemented on all of these devices, it essentially normalizes


companies running code on your devices.


And given that they have exclusive control over these databases.


And given that we see every day governments going to these companies right now, it's in


different countries, but surely can happen everywhere on the world.


I don't think this is necessarily a good thing given the trade off we're doing here.


This is so easy to evade.


And this is so easy to abuse at the end, it seems like there must be better methods of


achieving our goals here.


All right, that was it.


Check out code, subscribe, check out next ML news.


Author Interview - VOS: Learning What You Don't Know by Virtual Outlier Synthesis

Hello there, this is an interview with the authors of the paper Learning What You Don't


Know by Virtual Outlier Synthesis.


This paper presents a method to create what it calls virtual outliers, which are synthetic


out of distribution data points in the latent space of the model.


And then it trains that model to successfully recognize these points as out of distribution.


The paper performs very well on a wide variety of benchmarks.


And I've actually made a comprehensive paper review in the last video about this paper.


If you haven't checked that out, please do because I'll go over the paper, I'll explain


everything that's in it.


And the authors that I'm interviewing today have seen that review.


So we all start from a common level, and they're directly able to respond to my criticisms,


which is really, really cool.


So in this interview, we go over a lot of topics, but mainly I get my questions answered.


And we get a bit of a look at the behind the scenes of the research, how the research came


about, what the authors were interested in, how they solved problems that came up in between,


and much more.


I hope you like these paper reviews plus interview things.


Let me know how I can improve these videos for you by leaving a comment.


Like if you do like the video, subscribe or tell someone to subscribe and I'll see you


around.


Bye bye.


Hi, everyone.


Today, I'm here with Sharon Lee and Shifeng Du, who are authors on the Virtual Outlier


Synthesis paper and are joining me today discussing, well, the paper and as well as my attempt


at an explanation of it.


Sharon Shifeng, welcome to the channel.


Thank you for having us.


Thank you.


It's very cool to have you here.


So you have made this paper, it has gathered, I think, a fair bit of attention in the community.


Because outlier detection obviously is a big, big challenge, especially for security critical


applications.


And not only do you do outlier detection in classification where we usually see it, but


in like sort of the more challenging task of object detection.


So my first question would be, how did you even how did you come up with this?


Because it is not an obvious idea, let's say, to even tackle this problem.


Like what made you tackle the problem in the first place?


Yeah, thank you for the question.


I'd be happy to share, I guess, from a little bit behind the scene on the research story,


how it got started.


And by the way, we're really encouraged to see the interest from the community about


our work.


And so personally, I really I am driven to solve problems that are real, meaning that


has some connection to the real world.


And just like you said, I think out of distribution detection is one of those problems that really


matter a lot in deploying machine learning models in the real world.


And so sometimes when we're getting closer to this more realistic scenarios, that also


means problems are getting harder and more complex.


And this actually takes a trajectory to get there.


It's actually reflected, I think, in how the field of OOD detection has evolved and unfolded


over the years.


And so if you look at some of the early research we've done, including some other researchers


have done in the space, a very common way to evaluate how good the algorithms are, are


based on the benchmark, which is now seemingly seems quite artificial.


Like if you train a model on Cypher 10, and then you evaluate against data sets such as


Street View housing number or SVHN.


And so the seemingly simple task actually took a while for the research community to


make progress on.


I think over the years, we've definitely done a much better job developing algorithms to


reduce the false positive rate.


And so that's why we think we're at a better timing to start tackling some of the harder


questions on the object detection side.


And why object detection is very interesting and important, because that directly has a


better connection.


For example, if you think about self-driving cars, none of those images are simple as Cypher


10, which has a single object well-centered around in the scene.


In the real world, we are going to encounter inputs that have multiple objects in the scene.


And some of those are in distribution, which means they have been exposed to the model


during the training time.


And some of those are not quite.


And so I was really glad when Cypher joined the lab as well to start tackling some of


the questions.


So that's when we started the project earlier, actually last year already, last spring semester,


that's when we started.


So you were already in the space of outlier detection, let's say, in the broad space of


solving these types of problems.


And then, yeah, what made you decide object detection?


That's it.


Did you run across a problem?


Or is this just a natural continuation of the classification data sets?


That's another great question.


So why object detection?


So one of the, like you said, I think one of the typical scenario when we think about


where outlier detection or out of distribution detection algorithms are being used in the


real world is some of the high-stakes scenarios, like safety critical ones, for example, in


self-driving.


And that is kind of built on these object detection models, where not only we have to


perform classification, but at the same time being able to localize where the objects are.


So I think in terms of motivation, that just seems like a very natural application focus


to start with.


And of course, we have been, like you said, we have been in this space for working on


the problem, I think, since a couple years ago.


And most of the work we've done in this space are on image classification.


And so in terms of solution, I also wanted to share a little bit how we arrived at this


virtual outlier synthesis.


So I think the first motivation is pretty straightforward.


We wanted to go beyond image level OOD detection to have this finer-grained uncertainty estimates


that tells us at the object level whether things are in distribution or OOD.


I think figure one in the paper is kind of a perfect illustration for why we need object


level uncertainty.


So as you explained quite eloquently in your video, that this car is something the model


has observed, which is an in-distribution object, whereas this moose here is something


that was not exposed to the model during training.


And so this picture kind of highlights the complexity that an image can contain at the


same time, both in distribution and OOD object.


And therefore, we can't just derive an image level uncertainty measurement.


We have to go finer-grained at the object level.


And so that was the first, I would say, the higher level motivation on the object detection


side.


And then on the solution side, I want to share a little bit on how we arrived at the virtual


outlier synthesis.


So the idea, the algorithmic idea of this paper is largely inspired by one of our previous


papers on energy-based OOD detection, which was published at NeurIPS in 2020.


And so in that paper, we focused on image classification setting.


But from a learning algorithm perspective, we proposed this called energy regularized


learning, which in a nutshell is trying to...


Oh, I see your cat there.


He's walking by.


So in a nutshell, that learning framework tries to kind of tackle the problem of classification


by not only minimizing the risks in distribution data set, but at the same time, we are introducing


a regularizer.


And this regularizer has very similar spirit as what we're using here in this paper.


And so this regularizer is trying to kind of minimizing the risk or trying to pushing


the energy surface to be as distinguishable between known distribution versus unknown


distribution.


And so for the image classification setting, we used this technique or data set of outlier


exposure, which relies on an external different data set that's not overlapping with the in


distribution data set.


So that's actually one of the requirement or limitation, if you call, in that learning


framework.


And that does not directly translate into the object detection setting anymore, because


as you can imagine, in order to bring in an outlier data set for object detection, it's


gonna be tricky because you have to annotate through tons of images to make sure that at


the object level, things do not overlap with our training data.


And so this data collection itself is a prohibitive process and it can be very time consuming


and laborious and so on.


And so that also kind of motivate us to think, well, if there is no external data we can


rely on, is there any way we can devise some of the outlier data from the in distribution


data itself?


So that's where this whole idea started really is to think further how we improve on top


of the original learning framework that we had.


And then that's how you gather the ideas of synthesizing points that are not where the


data is.


Is there a connection to, I'm not sure how aware of, Yann LeCun has been pushing this


energy based learning a lot, sort of pushing energy up where data is, pushing energy down


anywhere else.


Do you see some sort of a connection to that?


Absolutely.


In fact, the work that I just mentioned on energy based out of distribution detection


that was published at New York's 2020 was precisely inspired by this whole energy based


framework from Yann LeCun.


By the way, the plural of moose is moose.


I didn't know in my video.


That's good to know.


I figured it out.


Not meese.


Yeah, so I mean, it makes sense.


You've seen my explanation.


And I think one of the criticisms a bit that I had was everything's pretty in this sort


of 2D landscape where you can show here's the data and there's outside the data.


But it gets very complicated once you go to higher dimensions.


For example, you had the picture here when you mentioned, we assume that the high dimensional


data are Gaussians and how, obviously your method works.


I think your evaluation is very thorough.


You measure on a lot of data sets against a lot of baselines and so on.


So obviously something works here.


However, do you have some, maybe some response to me, to someone who says, this does not


convince me that a Gaussian mixture model is appropriate for this really high dimensional


data?


Yeah, I actually like that question a lot.


So I wanted to maybe take a step back and first just to highlight one of the key, I


guess, the key insight and knowledge which I like about this paper aside from the distribution


or assumption that we've made here is the fact that the virtual outlier synthesis is


done in a feature space.


This as opposed to the original high dimensional pixel space is already a much, much lower


dimensionality.


So what you see here, this synthesis is completely done in this later representation or sometimes


we extract this from the penultimate layer of a neural network.


And so some earlier works explored, so we're not the first to kind of try to synthesize


outliers, but what we've done differently is to realize in order to regularize the neural


networks decision boundary, we don't have to go all the way to the original pixel space


where training a GAN model can be quite tricky and the convergence is going to be a challenging


problem on its own.


So that's one kind of step, which I think an important step that we've taken is to look


into a lower dimensional latent space, which in some sense makes this problem more tractable


compared to the original data space.


And now coming to the second point, I think when it comes to modeling the density of the


representation space, it's actually also a non-trivial problem, density estimation on


its own.


I think it's a notoriously hard problem in machine learning.


And so when we initially approached this problem, we kind of made this, I would say Gaussian


mixture distribution is the most straightforward assumption kind of to make.


And this first algorithmic framework, I would say we kind of just wanted to show even under


somewhat simplified assumption of representation space being Gaussian, you can still do this


virtual outlier synthesis tractably and train things end to end.


And from an empirical perspective, as you said, it actually works surprisingly well.


But that doesn't mean this has to be the only solution to it.


I think there are great opportunities that VOSS really opens up to is how do we perform


this synthesis in the feature space more creatively.


When it comes to the method itself, you have this overview diagram right here.


And I've attempted to explain this a little bit.


Did you find my explanation satisfactory?


Is there something missing?


Is there emphasis in the wrong place?


Or what would you add to so people really understand what's going on?


I think you did a phenomenal job explaining this whole pipeline, perhaps in a clear way


if we were to present ourselves.


One thing I wanted to maybe call out is this notion of this uncertainty loss, why we formulate


this problem that way.


So at a higher level, you can think of our learning framework as trying to do something


more than the typical supervised learning, say training a model based on cross entropy


loss.


There's a bit of element in the synthesis part, which is closer to this generative modeling


and density estimation, which we also talk about.


And so the whole framework combines both bits of supervised learning.


And also, there is some density estimation involved as well.


I think one interesting bit in the learning methodology is how we leverage energy as an


uncertainty measurement and to separate apart the known objects versus the unknown ones.


And so it's somewhat a problem that's not quite as complex as trying to estimate exactly


the pointwise density of p of x.


But rather, we're kind of piggybacking on a simpler problem of we just want this energy


to be estimated as a level set that is sufficient enough to separate these two parts of data


rather than getting every single point estimated correctly, if that makes sense.


The uncertainty loss you describe somewhere here.


It's down below.


And yeah, so I think I had this other comment where I said directly this loss sort of only


affects sort of the classification layer.


However, when you think about it, what you could do is you could simply take your Gaussian


mixture model, right?


And you could simply have your data point there.


And you could say, well, if it's unlikely, it's out of distribution, right?


I could simply map my inference data point, and then evaluate it according to the Gaussian


mixture model that I have at training time.


And I say, well, it's low likelihood, it's out of distribution, gone, right?


I wouldn't need all of this thing, which tells me that this loss does more than just, you


know, modify the last layer bit.


So there is a almost, is it fair to or is this correct, my assumption that there is


like this downstream effect on the entire model?


How would you like intuitively adding a loss like this?


What does it do to the whole, you know, the whole feature extraction pipeline that leads


to the latent space?


Yeah, that's a great question.


So perhaps to, you know, answer a bit more to that, if do you mind scrolling up a little


bit?


I think we have perfect.


Yes, that posterior probability right there.


So keep in mind, this whole training is done in an end-to-end fashion, right?


And then whenever we have an input object that goes into this network, we are optimizing


for this loss.


And this loss will be back propagated all the way, right?


Through this entire convolutional backbone in this object detector.


And so this objective L uncertainty is trying to kind of separate apart in terms of this


energy.


We'll get to this interpretation of the energy later on.


But at the very high level, it's trying to just push energy to be two sides.


One is above zero, one is below zero, right?


And if we look at this connection with respect to this posterior probability here, so we


can interpret energy as this density function for that data point P of x, perhaps plugged


in with some unknown factor that we don't know, right?


And so this energy does not precisely capture this density just yet.


But during this optimization process, we hope that through this propagation and minimizing


this objective, that this whole training would converge to a point where the density could


be more separable between the ID object and then the OD object.


So that's the inherent connection between the uncertainty measurement to the density.


So you sort of want, maybe reformulate it a bit, you want to coerce the feature extractor


almost to give you a space where you can be more certain about in distribution data, but


then like the less certain about out of distribution data.


Exactly.


So this is naturally, naturally, it is a harder problem, right?


If you go back to this, even in the two dimensional, the two dimensional case, I mentioned this


is like to separate three classes, I need three lines, right?


But to separate three clusters of data from their surroundings, I need like a very decision


boundary that's shaped, you know, highly complex, high dimensional, right, and so on.


What are the trade offs here that I make?


Are they severe?


Or did you find, you know, this works without severely impacting my accuracy as such?


What's sort of the, like, what do I give up when I employ this method?


That's a great question.


So I think there's natural trade off would be to say if we employ this regularization,


does that kind of hurt the performance, compromise the performance on the object detection side,


right?


And so we actually showed in the evaluation part in table one, if I recall correctly,


that this whole learning framework actually achieves, you know, both quite effectively.


It, yeah, I think it pretty much preserves the MAP.


So that's on the right most column where we show the, on the original, you know, Pascal


VOC and Berkeley Deep Drive task, how is that MAP, you know, changes.


It's pretty much the same or similar as the vanilla fast jar CNN without adding our uncertainty


regularizer.


And so overall, this learning framework kind of provides an actual layer of safety net


by pruning out some of the OOD object.


But at the same time, if it's indeed an in-distribution, you know, image, it can do as well.


Can you maybe, when we're at the experiments, I did not go into that at all in my explanation,


is there things that you want to particularly highlight or, you know, what should a reader


of your paper take away from the experiments other than you beat all the baselines, which


I think we've come to expect a little bit from machine learning papers, but you know,


what should like a reader, you know, take away as sort of conclusions from your experimental


section?


Totally.


I like that question a lot.


And I think part of the ablation in the paper is, I think it's quite interesting, you know,


going beyond table one.


We actually, you know, did some of the ablations comparing two different since this strategy.


And so I think table two is perhaps, you know, table three as well.


Table two is one of the interesting ones where we kind of try to contrast with, you know,


in terms of synthesize, we wanted to know, you know, whether this Gaussian-based sampling


is the optimal one.


There are, you know, works have done in the past, for example, directly using a GAN to


generate images, or, you know, you could also do mix up to have this interpolation in the


pixel space as well.


And then they're also, you know, utilizing noise.


I think those are all kind of natural alternatives for, you know, our outlier senses approach.


So I think this is one of the ablations I personally, you know, quite like.


And I also want to call out the fact that there is one previous paper, I think they


used these proposals with the large background probability as the kind of the negative samples


to regularize the model.


And that turns out to be, you know, also suboptimal compared to using BOSS.


I've also, so you had this decision to in the very last layer, introduce these virtual


outliers.


And I think in the video, I observed something like, okay, that helps if, you know, the out


of distribution data really looks different in the last layer.


However, if I have out of distribution data, but that exhibits the same kind of low level


features as in distribution data, that might not be the case, like in a vanilla network.


Is this also, let's say a weakness of your method?


Or would you expect that your regularizer would sort of automatically map these, these


types of outliers to different, like would construct the latent space such that they


are different?


Like, is it different?


Yeah, that's it.


Yeah, for that question, perhaps, you know, I can defer to Shufeng.


I think Shufeng has some good answer to that question.


Oh, yeah.


So yeah, so actually, I want to answer this question from two perspectives.


So first perspective, I think you're like mentioning some like, when a model actually


encounters some near in distribution OOD objects, so how does the feature space functions to


prevent the model to predict high confidence predictions?


So basically, we can potentially adjust the sampling threshold in ROS to see whether we


can create a tighter decision boundary in order to separate those in distribution objects


and those OOD objects.


And in addition, I think near in distribution OOD detection is essentially a very hard problem.


And there's a couple of works exploring this direction, but they are totally in the classification


setting.


So, so perhaps we can explore how to combine ROS with those techniques in the future.


So this is a first perspective, I think from the second perspective, I'm mentioning you're


like saying that how can we look at different semantic spaces, like different layers or


features.


Actually, I remember we in the paper, actually in the appendix section, we have reported


the OOD detection performance using the layer rather than the panoply layer for our licenses.


And actually, it seems like the performance is not as good as what we have for if we use


the panoply layer as the semantic space for ROS.


So basically, I think the reason is that the later layers in the neural network might be


more discriminative for classification.


So those more discriminative layers may be better for OOD detection and all licenses,


those synthesize all layers relies on the quality of those estimated covariance metrics


and those mean embeddings for each distribution class.


So I think that may be the reason for why we choose to use the panoply layer for ROS.


It makes sense as you go earlier and earlier, the less you can probably describe the data


using sort of this sort of a mixture model approach.


So I think, yeah, it makes sense.


I was just wondering, and even I think it's important to remember that we're still in


high dimensions.


And with being in high dimensions, it means that even if some of the features are the


same, you know, the moose will have four legs and so on, it will kind of look like a dog,


but not fully right.


So you'd still expect this in these high dimensions to be separated.


So maybe a bit to the research process, right?


You thought of this, you thought you're going to tackle this problem and so on.


Could you maybe share a bit of how the process, I think it's always, you know, you just see


the paper at the end and the paper is like, oh, wow, you have some examples here.


I didn't even, I think, show them much in the video.


So here you have comparisons at the bottom.


Everything that's green is detected as out of distribution, which is really nice.


The helicopter, I think was the most, one of the most shared pictures of your paper.


This looks really nice, right?


I think what people don't see much is the process behind it.


Like could you describe it a little bit?


Was there a time when you thought this wouldn't work or doesn't work or you don't know how


to go further?


How was it like to achieve at a system or arrive at a system that finally works really


well?


Oh, totally.


I'd be happy to speak on that.


Perhaps Shufun can add on later as well.


I think just like many other research process, nothing works out of the box immediately.


I think part of the research, the fun is really kind of going through the process and figuring


out a lot of intermediate obstacles.


And so to give you some example, some of the challenges I think really Shufun did a lot


of hard work in the process.


Just when we started the exploration, the first challenge we have to overcome is what's


the right evaluation, right?


How do we get this correct evaluation benchmark?


Because a lot of the previous work focused on image classification.


That's more or less well established.


And in order to evaluate this new setting, we have to actually gather and clean all of


these, for example, OD test images as well.


So that's some of the things you just have to kind of go through during the research


process.


And I think on the methodology side, there are also the challenges as well.


So one thing I want to share is there's actually one hyperparameter involves, which is I think


called the starting epoch, which is when you start adding this regularizer.


And so it turns out if you just train this whole entire loss with the object detection


plus the L uncertainty from the start, things are not converging as well.


So why is that?


Because at the beginning of the training, the representation is not quite well formed


yet.


And so therefore, estimating this density in the latent space is not also very reliable


and not to mention the sampling part.


And so that's where we kind of got a little bit stuck on is the performance if you train


from scratch is not really as desirable.


And so later on, we figured out is why don't we wait until the representation becomes more


and more form.


So this idea of kind of starting in a kind of later training process helped resolve this


issue.


And so that's kind of another example from behind the scenes.


But how did you get this idea?


Did you have some indication from some metrics that you logged or did you just sit there


and just try 10 different things and this one was the one that worked?


Or you know, I imagine you sit there, you try it and stuff doesn't converge.


Like it's just like, well, it doesn't work.


What can lead you to come up with the correct solution?


I think for this one, perhaps it's more natural because you know, if you think about how the


method works, it has to rely on some embedding space that has a somewhat clear structure


that you can perform density estimation and then sample from.


And so when things kind of doesn't work out, one of the, you know, we look at what are


the kind of possible major reflux that could happen.


This one would be, you know, the kind of the top one we are diagnosing into.


Excellent.


Yeah, I think that's a pretty neat overview.


Is there something else that you like to share about this?


Anything that we haven't touched on, maybe anything that you want to specifically highlight?


Yeah, I think I've talked a lot.


Shifeng, do you want to add anything that you particularly wanted to add on to?


I think I don't have any further comments.


Sharon has covered comprehensively about this paper.


Your code is online, right?


So people can go, can get into it, can experiment with it.


Yeah, I think that's pretty neat.


Yeah.


And with that, Sharon, Shifeng, thank you very much for being here.


And this was very enjoyable.


Yeah, thank you so much for having us again.


It's been fun, you know, chatting about the work and so on.


Thanks for inviting us.


Camera Module - Raspberry Pi and Python tutorials p.5

What is going on everybody and welcome to another Raspberry Pi tutorial video. In this video what we're going to be talking about is the Raspberry Pi


camera module. Now the camera module is probably the easiest sensor to use with the Raspberry Pi since it's just super simple plug and play.


So that's the first one that we're going to cover and then the next subsequent sensors are actually going to be connected to the GPIO pins.


Now on the Raspberry Pi we actually have a very specific port for the Raspberry Pi camera module. Now that port is right here.


Now a lot of times mine is actually up already but a lot of times it will be down. So to open the port there's these two tabs on the side.


You can grab those and pull up and that opens up the port. Now go ahead and connect the Raspberry Pi and generally like the backside of this pin,


or the ribbons rather, is this like silver pins and then on the other side you've got the covered blue. That blue should be facing towards the Ethernet port.


So go ahead and take the ribbon and insert it in. It should just slide in like this into the port.


And then when it's in there you kind of have to hold it with one hand and then use your other hand to push down the pins.


It's kind of hard to see with this in the way but anyways you hold it with this hand, you push down and then you use your other two fingers to push down on the pins.


Once that's done that's really all there is to it. Now your camera is connected and we're ready to actually plug in the Raspberry Pi and see the results.


Okay so now the Raspberry Pi is plugged in what I'm going to go ahead and do is change directory into desktop and I'm going to create a new file here.


I'm going to do this via the remote desktop but the main issue here is that it's going to want to display on the root, the actual Pi, like when we display video.


Now you could process video and all that but if you actually want to display video you're not going to see the video via remote desktop and you're certainly not going to see it on a non-GUI shell.


So I'll just show the monitor when it comes up but if you want to see the actual preview of the video it's got to be on the native screen, at least as far as I know.


So what we're going to go ahead and do now is come over, go into the desktop and first we have to actually enable the camera so sudo raspi-config and this is going to require a reboot actually.


Come down to interfacing options, hit enter there, camera is the first option and go ahead and hit yes to enable the camera and you're done.


And then hit finish and mine's already been enabled so I don't need to reboot but chances are you're going to need to reboot so go ahead and reboot and then once you do log back in and then once you log back in don't forget to cd desktop.


Well I'm already there but anyway desktop. Okay so now what we're going to do is we're going to create a new file.


I'm going to call this nano camera example.py and in here we're going to do some imports.


We're going to import pycamera and then we're going to import time and just to be 100% certain I'm actually going to control x, yes to save, yes.


It should be sudo apt-get install python-pycamera possibly, let's see if that works.


Okay yeah python-pycamera alternatively could be also python3-pycamera but we have both.


Anyway getting back into camera example.py, let's see, I'm getting lost, nano camera, yes.


Okay now we're going to define the camera object which will just be pycamera.pycamera and then we can do camera, first let's take a quick picture.


So camera.capture and then let's just save it as example.jpg.


And let's go ahead and in fact I kind of want to go into, let me pause this for a moment.


I guess we'll go, we actually will log into the remote desktop because the picture we should be able to see, it's just going to be the video feed that's not going to work for us remotely.


I'll hit okay and I'll just kind of have both of these up.


I could go to that computer over there, there's no real good way for me to record that screen so I just don't like to.


Anyway I'll move this over and let's actually just run this real quick.


So python camera example.py and we should now have yes example.jpg, we'll come up to the remote desktop, we can click on it.


And there I am giving you this lovely, lovely tutorial.


Okay so now let's go ahead and close that and this time we can see that well the image was actually flipped upside down.


So we can go back camera example and what we can say instead is, we'll just do it above here.


Camera.vflip equals true.


So that will actually flip the camera vertically, you can also do a horizontal flip if you wanted.


So yes and let's run that again.


And then come back to the remote desktop, click on the image and there we go, we're right side up.


Fantastic.


Alright, next what we're going to do is we can do a record, so we can go python or nano camera example, we don't need to capture again.


This time let's do a camera.startrecording and then we'll just save this as examplevid.h264.


We'll do a time.sleep 5 and then let's do camera.stoprecording and that will save the file.


So we'll get a 5 second video, so we'll go ahead and start that recording process.


And then when we're done we're going to use the OMX player, you should already have this on your Pi.


So let's come over here, let me open the terminal and we're not in desktop so let's change directory to the desktop.


And now what we can do is just call OMX player, OMX player, what did we call that video?


I already forgot, I think it's examplevid or something, examplevid, yep there it is.


Hit enter.


And it's playing I think on the other, I didn't see it pop up here.


You should see it on your own but let me just full screen this and then we can play that one more time.


And there we go, so there's the video that we recorded.


So for whatever reason it just won't show on the remote desktop.


Okay, so that's just some quick basics, you can also get just a camera feed like the actual preview.


So for example we could just run Python real quick.


From Pi camera we're going to import Pi camera, we're going to say camera equals Pi camera.


And then camera.start underscore preview, this may or may not work, my camera is still showing that it's on for some reason.


We'll see.


Oh, it looks like it's gone, we do need the vertical flip but regardless it's actually still, hello.


Anyway, okay that should be enough for the camera module, you can do all kinds of stuff with it.


You can do, let me pull up the, let's see, the opencv, oh no the robotics one, yes, yes, yes, yes.


So what you can do with this, all kinds of stuff of course.


But you can program a robot to shoot missiles at you when it sees your face.


So that's always fun.


Anyway, hopefully get your camera working, if you have any problems, questions, comments, concerns, whatever, feel free to leave them below.


Otherwise in the next few tutorials what we're going to be doing is talking about the actual GPIO pins on the Raspberry Pi and doing some pretty cool stuff with that.


NÜWA: Visual Synthesis Pre-training for Neural visUal World creAtion (ML Research Paper Explained)

Hi there. Today we'll look at Nuwa, visual synthesis pre-training for neural visual world


creation. This is by researchers of Microsoft Research Asia and Peking University. The paper


presents a model that can support a wide variety of image generation tasks, such as text to


image, where you give a piece of text and you get an image. This is a dog with goggles


staring at the camera up to something like video manipulation, where you want to change


the frames of a video according to a piece of text. For example, the car is reversing


instead of the car is driving forward. Now, you see there's not always text in the loop.


Sometimes it's just an image. Sometimes it's a sketch. Sometimes it's just a video. So


all of these kinds of tasks are supported by this model. And this paper goes into how


the models architecture is done, specifically how the a transformer architecture essentially


an attention mechanism is able to handle such large data points, essentially, contexts,


not only going to images, but beyond images to multiple frames of video. Hey, oh, this


video is sponsored by clear ml clear ml is an ML op stack that is fully open source,


it can do experiment tracking experiment orchestration deployment, it has model and feature stores,


it is a complete package of ML tools. Now what I want to highlight in particular here


is this self hosted tier self hosted is a first class citizen for clear ml everything's


open source. Therefore, you can look at it, you can audit it, you can extend it however


you want. And you can host it on your servers. There's also a free tier that is available


in the cloud. So you can get started with whatever you need in the cloud. And then once


you need more features, you can go to a more professional setup if you don't want to self


host. If you love open source, then clear ml might be the way to go. It is an end to


end stack from experimentation all the way to serving it's vertically integrated, makes


your life a whole lot easier. And it is appropriate whether you're an individual running experiments,


or an entire team. Now one of the core pieces of clear ml is of course their experiments


tracker. It's super easy to set up it needs like a single line of code. I guess that's


two lines. But you know, who cares? It integrates with pretty much any tool there is. And not


only does it record your metrics like you're used to, it also fully grabs all the console


output of your experiments, it grabs any artifacts that the run might have produced. And most


importantly, it clearly records not only your hyper parameters, but also the other parameters


of your environment, such as the path and the machine you ran it on, and your dependencies.


Another really cool feature is that it allows you to compare different experiments. For


example, here, it shows you what part of their configuration was different. So you're able


to pretty quickly figure out what made the difference in any particular run. And of course,


you can grab a bunch of experiments together and then analyze them next to each other.


So now there's no excuse anymore for blaming your tools, any fault in your machine learning


project will be yours and yours alone. If you use clear ml, isn't that a promise? So


I invite you to go over and check it out at clear.ml. And thanks so much to clear ml for


sponsoring this video. And let's get into it.


So yeah, we'll go into the paper, we'll see how they do it. I do find this this opening


thing right here is a little bit overstated, because a lot of these things aren't coming


out of the same model, but the model is fine tuned on different things. And I also find


the papers a bit unclear on some of the details. And if I understand correctly, there is no


code yet that we can look at maybe that's going to be released. Maybe not who knows.


To the name new war is, you know, there's this umlaut, which we do have in German, but


I don't believe this is a German, German inspired name or or or any sort of Nordic language.


I do believe this comes from the symbol in pinion that has also is represented as an


umlaut on the you. It took me like so long to figure out that you have to type a V in


pinion to get that output. I just couldn't spell words like new for a long time. But


now I can. So I do believe this is pronounced new war. But correct me if I'm wrong. Also,


many things to Andreas, who helped me prepare this paper a little bit, gave me some inputs.


This is very much appreciated. Follow Andreas on Twitter. He also often posts updates for


our paper discussions on discord. So very helpful. Thank you. All right, let's get into


it. So this model is something like an image GPT model. If you know image GPT image GPT


is essentially similar like a pixel RNN where you have an image, you want to produce the


image sort of pixel by pixel left to right, top to bottom, you produce just one pixel


after another after another after another. And you learn this, how you would learn a


language model, essentially just pixel by pixel. And you can support tasks like completing


images, where you simply give you everything here, you already set pre computed, and you


simply let the model infer these pixels right here. Or you can support things like image


manipulation by simply, you have a picture right here. And or I'll say that's the cat.


And you simply cut out part of the image. So you cut out this part or something, you


let the model fill it in. So you could do things like in painting or something like


this. This is supported by image GPT. Now the problem with something like image GPT


is that if you want to have this as sort of a language generation task, then your context


size is you know, if you predict the pixel on the bottom right here, the context is like


all the pixels in the rest of the image that you've already generated. And if you have


something like a 200 by 200 image that is 4000 previous pixels. Now 4000 is just about


no is it it's 40,000. Sorry, sorry about that 40,000. That is definitely outside of the


scope of every transformer that we have. And beyond that, if we now look at video and video


is essentially just a stack of images, right? So you have an image frame, the next frame,


and the next frame. If you look at that, if you want to produce a single pixel right here,


not only do you have to take into account all of the pixels of the image that you've


generated so far, but also all of the pixels of the previous frames that you've generated


so far, right? And that definitely blows the context of any transformer that is infeasible.


So this model here very much is about how do we make this feasible? The answer is going


to be a twofold. First of all, we're going to encode all of the data into a common space


that is kind of discrete in latent space, and is way less dimensional. And the second


answer is going to be we're going to use a local attention in order to work in this latent


space, and finally generate the output. So this is an overview over the model, I do find


it a little bit lacking as a picture. But you can see that in general, we use these


encoders and the encoders, they take care of bringing the data, whatever the data is


into a common representation right here. The common representation is going to be a essentially


a three dimensional cube where each element is an embedding vector. But we're going to


look at that now. So how do we encode text, our goal is to our goal is going to be to


have a latent space to have an encoder for any kind of data. And after the encoder, the


data should be in sort of a latent space. And that latent space should be, if possible,


kind of discrete or quantized. And we're going to use, we're going to use some methods that


already exist. But for text, that's pretty easy for text, the encoder is simply it can


be the identity function, right? Because if I have a piece of text, like a cat, whatever,


if I tokenize that text, that is already tokens. So right now, if we make if we do a language


modeling or any sort of language processing, the first step is tokenizing the text, and


then associating each token with an embedding vector. So this is going to be nice, it's


going to be a set or a sequence of tokens. And that's exactly the representation that


we want. So for text, everything's good, we have a sequence of tokens, we have a codebook,


usually, which is sometimes in this language modeling, that's called the embedding matrix,


that's at the beginning of the model. So every, every code vector, every token is associated


with a vector. So we can look up that vector in the codebook, replace the token by the


vector, and then process the tokens as vector embeddings in the subsequent model. We want


to do the same with images, right, we want to get an image and we want to bring it into


the latent space as a set of discrete quantized tokens. Luckily, there is a technique how


you can do that. And that's called the VQ VAE. So if I have an image, let's say, in


our cat, what I want to do is I want to have an encoder, such that it results in a set


of latent tokens. Now, VQ VAE is interesting, because what the result is going to be, is


going to be, it's going to be like an image, but that image is going to be very low dimensional.


So here, we may have 200 by 200. But over here, in this case, we have like three by


three. And these aren't, in fact, pixels, but they are tokens. So these will be vector


quantized, there will be a codebook, they call it B. And that codebook will be vectors


for each token. And what the encoder does is it essentially reduces the image down to


a representation that is three by three. And then every single pixel in that three by three


matrix, every single entry right here is going to be clamped to the nearest entry in the


codebook. That's the quantization step. If you if you don't know much about this, you


can look up vector quantized vector quantized anything pretty much, but vector quantized


VAE is sort of the main reference right here. It's the encoder encodes in a continuous fashion.


And then there is a discontinuous step, a discrete step where we say, okay, we there's


there's latent space. And we have this codebook vectors here, and they're going to live in


that latent space as vectors as points in that latent space. And if my encoder encodes


an image, and I take any pixel right here, and that pixel might come to be here, I don't


use the pixel or I don't use this latent token as is going to clamp it to the value directly


of that codebook vector. So all I end up with is a selection of these codebook vectors.


So at each point here, there will be one of those codebook vectors. And I can equivalently


say, if I like number them, this is 1234, I can equivalently say these are essentially


tokens. So token one might be this might be this might be one, this might be two and two,


three, four, four, four, four, right. And from this, I can then have a decoder again,


that produces back an image. And the image, of course, is now only produced from this


latent encoding, you might think that is way restrictive. But it actually turns out to


be very, very powerful. So instead of using the exact encoding, we use the quantized encoding.


And if our codebook is large enough, you know, you can encode quite a number of things. Like


if you have 1000 tokens, you can imagine token one could be, you know, there's it, there's


kind of a tree and token two is like a tree stump. And token three is like, well, a tree


that is like a has needles like a needle needle, like a pine, and so on. And then your latent


description here just kind of roughly outlines the broad shape of the image. So not necessarily


exactly what's where, but it just says like, you know, in the top right, there's a bunch


of pine trees, and in the bottom right, there's a road, and so on. So it's, it's a latent


tokenized or latent discrete tokenized representation of the image here. And you can already see


that this is way beneficial, because now we're only working in a nine-dimensional, sorry,


nine tokens, whereas here, it's 200 by 200. Now, we don't have to forget that each of


the also each of these tokens, obviously, is going to be associated with a vector. So


this is not nine dimensional space, but it's nine times whatever the vector dimension is


that is associated with each token, as you know, like this is not 200 by 200, it's actually


200 by 200 by three, since every pixel has a vector of dimension three associated to


represent color. Right, this VQ VAE is trained as an is if I understand correctly, this is


the first part, where the model that the paper isn't exactly clear, what happens right here,


I'm not sure whether this is trained end to end, or whether they train the encoder and


decoder here ahead of time. Because they have different formulations, they say, like, after


training this, we do that. And I'm not sure. But essentially, they train it. Like, so here


is how you obtain the latent representation, you send an image that's I through the encoder,


that's E, and then you select the Z, the these are the latent vectors, set the Z or the now


these are the tokens, the token indices, such that you set the Z according to what's the


closest vector from the codebook from the codebook B. So you can see the J or the indices


into the codebook. So the Z will be for for a token i, what is zi will be what entry in


the codebook vector is closest to that representation that the encoder produced. And then the reconstructed


image I had is simply going to be and I'll go with my latent representation to the codebook,


I actually get out the vectors, the entries of the codebook, I shove that into the decoder,


which is G, the generator, I guess. And that gives me the reconstructed image. So how am


I going to train this? It's easy, I want that my produced image is close to the original


image right here. I also want to train the codebook, which is B, to be close to what


my encoder produces. So I want the codebook to be useful. And that means the codebook


needs to be able to sort of just describe the things that the encoder produces, right?


So the code, I'm going to draw the codebook closer to the encoders output right here,


the SG is a stop gradient, which means that this part of the loss affects the codebook.


But also we have the symmetric part right here, where we're going to teach the encoder


to produce things that are better encodable by the codebook. So here, the stop gradient


is on the codebook, which means that this part of the loss affects the encoder is quite


common to split up two losses, even though this could be in one loss, right? Since it's


symmetric, it's quite common to split it up into two parts, each one having a stop gradient


makes things more stable. Alright, so is this actually Yeah, probably. It's it's just a


framework, framework specifics right here. I don't think s SG is a valid mathematical


thing anywhere. This really refers to the stop gradient functions in in TensorFlow or


in pytorch. In addition to that, they say, well, the VQ VA is sort of too strict a little


bit. So there is an extension called VQGAN that changes the VQ VA objective a little


bit. So they say they add two things right here. One is a GAN loss, which I'm going to


guess is this one right here. So you can see they introduce a discriminator that discriminates


between real and fake images. And I'm going to guess that that here is the loss for the


discriminator, right? Because you want the discriminator to recognize real from fake,


which means you need I and I hat. But I don't see I don't see the loss that would be added


to the generator. Because the generators loss, I don't think that would necessarily include


the true image. But I might be wrong, because yeah, so I mean, the generator would simply


not care about the first part right there, if even if you included it. But you know,


they introduce a discriminator, which we know can help. And they also say they introduce


a perceptual loss. And they simply write this down as we're going to pass both the original


image and the generated image through a CNN. And then we compare the two. This is in contrast


to comparing the two images directly. As you can see, they say that this is meant to ease


the exact constraints between I and I hat and focus on high level semantic matching.


I don't exactly know what the CNNs are, if they are trained as well, or if they simply


take like an off the shelf ResNet 50, pass the images through and compare the last layers


in order to say, well, I just want the latent representations to be similar. I don't actually


want the images to be similar. They also don't say whether that replaces this, this loss


up here, or whether that's simply in addition to that loss. Again, we don't know. They further


they further say that you could do the same thing for videos, right, you could train like


a VQ VAE VQGAN for videos, because after all, videos are just a stack here that we saw a


stack of, of images. But they say that didn't work out well. So what they do is they simply


treat each frame of the video as an image. And they pass each frame through this image


encoder right here. And they simply stack the outputs or they stack the latent representations.


So that'd be from the first frame, then from the second frame, from the third frame, and


so on, they stack them like this. And that gives you sort of a tensor. Now, keep in mind


every single entry right here, for example, this entry or this entry or this entry, every


single entry is associated with a vector. So this is ultimately going to end up in a


four dimensional latent tensor that you work with. But we can represent it as a three dimensional


tensor of tokens, where each token will be an entry in the codebook. So how is that a


common representation we saw? So the text is 1D of tokens or 2D, if you consider it


as vectors, images are 2D as tokens, but 3D as vectors, and video is 3D as tokens and


4D as vectors. How can we make sense of this? And we combine all of this by simply introducing


a dummy dimensions. So if you've ever in like NumPy, you know, you index your vector, sorry,


your vector x with like, you know, I want everything, everything and none. That's one


way you can also use the expand dims or unsqueezing PyTorch or anything like this to make it compatible


and essentially use the broadcasting functionality of the frameworks. That's essentially what


they do here. They say, you know, we have an image, we have the latent representation,


we simply add the placeholder dimension of one, since images have no temporal dimension,


it's just height and width. But for videos, this one would be, I guess, not a one. So


if you can bring them into the same space, by using dummy dimensions and broadcasting,


if necessary. So now everything essentially is a 4D latent tensor, you can bring in text,


you can bring in images, you can bring in videos. The next thing we want to do, and


again, I don't know if these are pre trained the encoder decoder, or if these are trained


jointly, I don't know. The next thing we want to know is okay, right now, this is simply


encoding and then if we ship the representation through the decoder, it's right. So if we


ship it through the encoder, and then through the decoder, it's going to result in the same


image or in a very similar image, right? So here is going to be like another cat. Like,


how does that help us? Obviously, there needs to be something different, right? We want


an image right here, I'm going to put it through the encoder, we're going to get its latent


representation. And then we need to do something, something with the latent representation,


get another latent representation, then decode that. And then we get some sort of a different


result, right? So different resulting image right here. So this is the same for like image


completion and so on. The question obviously, is what happens right here. Now, there is


where the sort of the transform or the attention layers come in. Until now, we've had classic,


I think these are the convnets and so on these encoders decoders, like you'd be used to if


these are images. But now what we do is we have essentially a model that transforms the


that transforms the latent representation to do meaningful work. Okay, so how is that?


How is that done? They differentiate two things right here, they differentiate context, which


is here on the left, broadly, which they always or sometimes denote with large C context here.


And as context, they count things like input text, or input sketches. And the reason it's


context is because those things aren't output. Those things are never given in completely,


the model will never have to produce them, you always input them, you either input them,


or you don't input them. But if you do input those things, it's conditioning information


that the model can look at as a whole, right, you always enter the full text or the full


sketch, you never enter like half a sketch, the model can't produce sketches, the model


can only produce images, or image frames, frames of a video. So that is the decoder


is only images encoders can be for text for images and for sketches. So the part over


here, they would generally call the output y, even if like half of it is actual input


into the algorithm. So here you can see the input is the part of an image. And the output


is the remaining part of that image, or the input is the video frame, the output is the


future frames, right? So yeah, so that is the output part. And this should remind you


sort of of the original transformer architecture. So the sequence to sequence task is you have


sort of sequence one, and that is always given in full. And then you have sequence two, that


sequence two, that maybe maybe you are given not nothing at all, or you're sort of given


an initial initial token right here, or you're given kind of a prefix of what you have to


generate. And then you have to go on completing sequence two. Now, if you don't have sequence


one at all, that's a decoder only architecture, that's also possible, you can condition on


nothing. But the most general architecture has these two sequences. If you remember the


original transformer, it was exactly like this. And then wait, let me pull this down a bit.


And then it had sort of a stack of transform of attention layers here, and a stack of attention


layers right here. And what you do is within the attention blocks, you'd had like self


attention, where things attend to each other attention here, attention, attention, attention.


And then inside this block, you'd had attention also by with itself. But then also, you'd


had layers where attention would go from the y part. So from the output part to the context


part. So you would let the output right here in a layer collect information from the context


by doing what they call cross attention. In the original transformer paper, I think it's


still called cross attention right here. Both are the same operation, both are both are


attention operations, it's just a matter, you always have a queries and keys, sorry,


that's an E keys and values. If it's self attention, all of these are generated from


the same input. And if it's not self attention, then this, for example, is generated from


the y input. And these two are generated from the context information. And that essentially


means that y is requesting information from C. So y is looking is attending to information


in C. Okay, same thing here. What they have this layer called 3DNA. Now that's the entire


layer name is 3DNA. That is 3D nearby self attention. Okay. So they say this is based


on the previous 3D data representation. So 3D, they essentially mean 4D, but 3D tokenized


and then each token has a vector as a vector, but there, the 3D comes in when they do when


they discuss how they do their attention. By nearby, they essentially mean local attention.


So what they're going to do is they're going to do local attention in this 3D tensor. That


is, I think what I what I could gather so far, they formulate this in a general way


right here. So what you'll do is you'll define this for two tensors x and C. And sometimes


those are the same and sometimes not. So specifically x can be either C, in which case it's self


attention, or x can be y, in which case it is cross attention from y to C. I guess C


could also be y, in which case it is self attention from y to y. So yeah, I'll just


make it a little bit confusing right here. In any case, it's just a matter of how you


compute the how you compute the keys, the values and the queries. As you can see, the


queries are the queries are always computed from the entire the queries are always computed


from the entire vector or vector tensor x. So whatever is producing the query, the entire


thing is producing the query. However, for the keys and values, what you do is you define


a local neighborhood. So now we care specifically about how do I produce y at location i j k.


You have to imagine we have this 3d representation, which is essentially a big cube. That cubes


elements are these tokens, right? So this is, you can imagine it as a just stack of


video frames, but in latent space, right? So in latent space, we have the stack of video


frames of the latent encodings of the video frames, if it's just a single image, right,


you broadcast and so on. But in in that case, we wonder how from this, we need to produce


sort of the next layers representation, which is also going to be a cube, just like it.


So as much as in an attention layer, the input is a sequence of tokens, the output is a sequence


of tokens as well. In this, it's the input is a, I guess, a cube of tokens, and the output


is again, a cube of tokens. So we're going to do that, we have an, we produce the output


for each location, we define a neighborhood. So if we want to predict this, this would


be y at i j k, we're going to search i j k over here, which is going to be, I guess,


right here. Okay, so this is i j k, the same location, then we're going to define a local


neighborhood around that thing. So that could be just, it's again going to be a cube like


this, that is just a little bit bigger. And they are using as far as I can tell, they're


using three by three by three cubes right here. So they're going to define a neighborhood.


And while the queries are generated from sort of the entirety, right here, of the, from


the entirety of the tensor, the keys and values are only going to be computed from that cube.


So instead, if this is height, width, and height, this is s, let's call that s, the


temporal dimension, and width, even though this is already in the latent space, it would


still be very, very expensive to compute self attention or cross attention. When every single


element of the cube attends to every single other element, right, that's essentially what


we'd have to do in an attention layer in text, I have a sequence. And every sort of every


part of the sequence is able to attend to every single other part of the sequence that


is not feasible, if you have a 3d cube, even if it's in a lower dimensional latent space.


So what I'm going to do is I'm going to say, okay, if I want to, if I want to compute this


output right here, I can only attend to a local neighborhood around this output here.


So that's, that's that. So the queries, I can compute once for the whole tensor. But


then if I so that's, I can compute the queries for the whole tensor. But if I want to produce


a particular location, the only place I can attend to is the keys and values of a particular


local neighborhood. So essentially, that piece of the cube here can only look at the local


neighborhood around its locations in order to aggregate information. That is its local,


local attention, either local cross attention or local self attention. So we define the


neighborhood and produce the query for a particular location. I'm not sure if that should be x


ijk or not. Not sure. But yeah, you can see that the the keys and the values are certainly


specific to a location, they include this neighborhood right here, this n neighborhood,


the n neighborhood is defined as this set right here, which is simply what I just said


that that cube. And then I compute the softmax simply as this is I think there's a mistake


right here. This should be this should definitely be not here. This should definitely be here.


Yeah. So I'll compute the softmax like I would in the outer product between queries and keys.


Just in that neighborhood, and then aggregating the values according to what the softmax of


the routing table gives me. And that's how I produce this output right here. Okay, so


I can do that all in parallel, I can essentially produce that next tensor right here of the


latent representation. And yeah, that's that. Now, I just said I produce it all, by the


way, there is a you can see that reduces the complexity from sort of this square to simply


every location attending to its local neighborhood. So that reduces the complexity by quite a


bit. So for every location, that's this part, I have to attend to its local neighborhood.


That's this part. There's also positional encodings, as you can see, right here. And


what we're going to do, we're going to first have a stack of layers of self attention for


the context, like we saw in the original transformer. So we're first going to have a stack of l


layers right here. And after that, we're going to have a stack of l layers here. And each


of those l layers can do either self attention or cross attention. But as far as I can tell,


it's it's kind of different than the original transformer. Because here you can see the next


layer here is produced from the last layers. And likewise, here, if I produce the I, the


next layer is produced from the last layers of y, but also from cross attention from the


last layer of y to the l layer of C, which means that it it only can look at the output


layer. So the arrows I've drawn here can technically not happen, but it always has to look at like


the output layer up here. I guess that's a way to do it. I don't think that's the exact


same thing as in the original transformer where you really have, as I've shown the arrows


here, it sort of attend to the same height, I might also be wrong in this. Or it's a wrong


formula right here. That is also completely possible. Now, you can see there is I've masked


this, there is also this part right here. So what we're going to use is we're going


to use causal attention. So we're only going to attend. I said you can do it all at the


same time, you have to do a causal mask, you know, like in things like GPT, where I produce


one token at a time. When I produce this token right here, I'm only allowed to look at the


token that I've already produced. And that's the exact same right here. In fact, we're


going to produce this representation, we're going to start like at the top left at time


step one. And we're going to produce the whole image at time step one pixel or not pixel


by pixel, but element by element in this representation. And then we're going to, once that is complete


that video frame, let's say we're going to go to the next step and again, do it element


by element. So this is really a giant autoregressive model. Now you can with causal attention,


you can you can train at the same time, but during inference, you only actually attend


to the things in front of you. This formula, in fact, doesn't doesn't exactly I don't is


this is this correct? Because here it says everything needs to be smaller, which to me


would mean that, you know, if I'm let's let's just make it for 2d. And let's just say it's


smaller, I smaller j is the question of if I produce this pixel right here, technically,


I should have access to everything up here and the row so far, right. But with this formula,


what it would mean is that I have access to only whatever is to the top left of me, like


this part right here. And I don't think that's the case. I think this is just sloppy notation


right here. See, yeah, this denoted generated tokens for now that I don't think is correct


to express it like this. Seems shady. It's all it also doesn't tell us exactly in which


order the pixels are produced. Though I think it's first within a time step and then across


time steps. So yeah, that is that is that. Now let's get to the training objective. So


I hope you can see that this is one layer of this three DNA. And we have l layers here


and L I think is 24. In their models, we have l layers on for the context, and then also


l layers of cross and self attention. And ultimately, we end up up here with the final


representation. And training we can do in parallel with causal masking. But inference,


we have to do element by element. So that's why they praise that their model is reasonably


fast. But I think it's still like 50 seconds to produce one one image or something like


this. And that's why. So the training objective, and here is a little bit where they they,


yeah, where, again, I find it to be quite unclear. So they say they train it on three


tasks. And if I understand correctly, they train on these three tasks simultaneously.


So they have three different data sets. One is a text to image data set where you can


see right here, you produce an image and you condition on text, okay? You and you can see


that this lower than T simply means the elements are the tokens lower than T. And you go from


T equals one until height times width. So it's an image. So it only has these two dimensions.


So and you produce, I guess, pixel by pixel. See that that I don't I don't know what what


does y mean here, if it's really the output y, then you know, you have that generator


here and the generator probably doesn't go pixel by pixel that I don't know, maybe it


does, maybe it actually does. In any case, you have these three tasks. So one is text


to image from a data set that does that. One is video prediction, where you simply input


a piece of a video here, the C here, that is like a no op. So that is the special word


none. So because, you know, you still have to input something, but if you have no text


conditioning, you simply input a dummy. And then the loss goes over also over the time


steps. And there is also text to video to where you'd input text and video so far, and


you'd output the rest of the frames. So that is, yeah. Again, so here, probably the loss


doesn't necessarily go across all the time steps since part of the video is already given.


But yeah, I guess we'll have to wait for the code to see what really turns out. Most notably,


you can see that the conditioning information right here is sometimes it's video, right,


because it's sometimes video is kind of conditioning implicitly by us already being part of the


output. But there is no, for example, sketch conditioning right here, it's always either


text or nothing. And this is pre training. So that means everything you see to do with


sketch is then fine tuned. So that that was my when I first saw this, I thought like,


oh, wow, they, you know, train these jointly, everything's joint. And then the same model


can do all of these tasks. And it turns out, no, actually, most of these things are then


fine tuned down the line. Now they do show that the font, the pre training actually helps


quite a bit. But you have to understand these are in fact, fine tuned. Also, you can immediately


see that something like video manipulation is not actually video manipulation, like the


model doesn't care about that, about these frames right here, that the car what the car


is doing, the model doesn't even see this, you simply input the first frame, and then


you let it generate the next frames based on this text right here. So it's not necessarily


manipulation, as much as I give you the beginning of a video and the piece of text and now please


predict the video based on the text. It's a bit like this here, except you already have


the first frame. If, if I understand correctly, but I think I think I do that there's really


no other way, I guess, I'm not sure. Maybe they actually into input into maybe they input


it into the context right here. But I cannot imagine that. In any case, maybe I completely


misunderstand this right here. But these are the tasks, they give some implementation detail


about how the how the latent spaces or you can see that there's a latent space of dimension


1280. Yeah, the local neighborhood is of size three by three by three, or three by three


by one for images when they're lonely images. And it's the regular attention mechanism if


it is text. Alright, so that is it. And these the next slides are results experimental results,


I want to highlight a few. So here are things they can do they compare, for example, with


Dali, which is a model that is explicitly trained to produce images from text, right?


Whereas this model right here is sort of a multi purpose model. And you can see that


in general, either the results are comparable, or better. I mean, it's, this is at this point,


it's kind of argueable, you can measure it on certain data sets. For example, here, they


they specifically praise this picture right here, where they say, Oh, this is very clear


and consistent. And this other state of the art model is not as not as good. I do like


some of these outputs right here. Playing golf on grass, the baseline model, you can


see the baseline model just just screws up though I do think there aren't many days for


some tasks, there are just no, no baselines available because they kind of invented them


themselves. But you can see that when there's baselines available, the baselines, usually


they either Yeah, they don't necessarily do so well, either. So in this case, this is


doesn't really seem to be Yeah, I guess it's some kind of a human ish thing. But this,


you know, looks looks fairly neat. And you can see the resolution is also bigger than


the resolutions of the competitors. That's, that's pretty cool. You can also, as I said,


this is now fine tuned, right? If you actually want to sketch to image or sketch to anything,


you are going to have to fine tune it on that data set. But if you do, you can see that


the results are very, very cool, very accurate. So this is the input, I'm going to guess that


green thing here is the vehicle class or even the bus class. And yeah, the outputs are pretty


convincing, honestly. So yeah, if you if you want, you can look at the metrics yourself.


They have a bunch of more, more examples right here. As we said, specifically, things like


in painting are doing are quite possible right now. So you can say, I want to only produce.


So I want to clamp everything to the original image except this region right here, you can