From the course: Grasshopper: Tips, Tricks, and Techniques

Setting up training data in Crow

- [Instructor] Welcome. This is the second in a series of five videos that focus on machine learning within Grasshopper 3D, specifically using the Crow plugin, because Crow does such a good job of organizing its components in a way that explain or illustrate the principles of neural networks and machine learning. So in this specific video, we're going to focus on preparing a face mesh for training the neural network. And the goal is to create a neural network that can recognize the features of a face. So it can recognize the nose, the chin, and the cheeks of any arbitrary mesh that's shaped like a face. So it can determine which parts of the mesh are which parts of the face. And then we can use that classification, that organization. to orient mask geometry. So we can optimize the development of the shape of respirators to match different faces. So here's our sample that we're going to use for training. And what I want to do is prepare this sample so that I get rid of the location of the face in space. Cause that's not what makes it a face. What makes it a face are the relationships between the different pieces of the face so that it can be recognized if it's rotated around or if it's moving in different locations in the Cartesian system. So I'm going to go to mesh, face normals, and we're going to use the center point of each face and the normal each face as a way to start off recognizing this geometry. So I'm going to go math, average and we get the average of all the center points. And then I'm going to create a vector from that average point, which is sort of the center point, you can see there, like a centroid for this geometry, to the center point of each face. I'm going to get the normal as well. So I'll go back to params, vector. Okay. So now I have the orientation of each face and I also have the relationship between the face center point and a sort of middle centroid of the face. And then the last thing I'm going to add here, as a way to describe this form, I'm going to go to vector plane, plane fit. I'm going to fit a plane through all these points here. You can see the plane right there, and I'm going to project the points onto the plane. What I'm going to do is get basically a flat version of the face that kind of tracks the relationship between the boundary of the outside face or an average of that boundary and each point on the face. So we'll go to plane and we're going to get the plane coordinates for each of these points. And this is basically projecting without using the project command. So point oriented, I'm going to plug in the plane, plug in X and Y. So now I have those points on that plane. I'm going to go to mesh, triangulation, convex hall. And this just gives me the outside boundary of that bunch of points. And then I'm going to get another vector here that is, I'll go to curve, curve closest point. And I'll get a vector that's from these points, the center points of each face, to the curve, right? And I'll store that as a vector as well. So I want to go to point. So starting from the closest point of the curve to the point itself, and now I'm going to flatten each of these, I'm just going to flatten them and then I'm going to graph them. That way I know that they'll always be consistent in terms of the data tree structure. So I'll go to vector, point, and I want point to numbers, and this I'm going to graft. So these data trees should be the same and I'm actually going to simplify them. So now we have consistent, simple data trees coming out of each one. We're going to merge those together by using the merge component. Now I should have a set of nine numbers come down here. And those nine numbers should be an effective description of that mesh object but a description that is independent of its location. And there's probably a lot of ways to do this better. This is just an initial attempt. So if I were doing this and really looking to ensure performance I would probably spent a lot of time tweaking and refining the way I did that conversion from a regular mesh object to these sets of points that describe that mesh object. But for our purposes, I think this will work. So I'm going to just cluster this up. So it becomes basically our little tool that we can use to convert meshes into descriptions for machine learning training. All right. So now we have that set up and in the next video, we're going to look at how we actually do our classifications of the same mesh so that we can run our training on our actual neural network. And before we do that, we can plug in these numbers, cause this is going to be our training in data. And I'll see you in the next video.

Contents