Video Summary and Transcription
The video highlights the Keras ecosystem's ability to simplify deep learning. TensorFlow offers tensor manipulations, automatic differentiation, and versatile deployment options including TensorFlow Lite and TensorFlow.js. Keras provides high-level APIs, making it easy to add layers and handle loss calculations and training loops. Keras Tuner automates hyperparameter tuning using algorithms like Bayesian optimization. AutoKeras makes machine learning accessible with minimal code, supporting tasks like image classification and regression. Beginners can start with AutoKeras or beginner-level courses. TensorFlow's Eager Execution offers flexibility for researchers. AutoKeras supports complex scenarios like multi-model data and multitasking. Time series forecasting will be available in AutoKeras by year-end.
1. Introduction to TensorFlow in Keras Ecosystem
Hello, everyone. I'm very happy to be here at MLConf EU with you guys and thank you very much for the invitation. My presentation is about boost productivity with Keras ecosystem. We're going to highlight four features of TensorFlow. The first one is for tensor manipulations. The second feature is about automatic differentiation. Another important feature of TensorFlow is about deployment. It can be deployed anywhere for a model implemented with TensorFlow. TensorFlow is really about performance and scalability. But how do we really leverage the power of TensorFlow?
Hello, everyone. I'm very happy to be here at MLConf EU with you guys and thank you very much for the invitation. And my presentation is about boost productivity with Keras ecosystem.
So there are many members of the Keras ecosystem and the first one we're going to introduce is TensorFlow. I believe many of you guys have heard of it. It's a very powerful foundation for all the deep learning solutions built on top of it. But today, we're going to highlight four features of it for you to see how other members of the Keras ecosystem going to depend on these features to build something more.
The first one, we all know it's for tensor manipulations. As you can see, we have A and B as two by two matrix here, and you can do A plus B or C or exponential of D with them. This is supported by TensorFlow, or a source of mathematical operations on all those tensors. And the second feature we want to highlight is about automatic differentiation. It means you can calculate the gradients automatically without manually computing any of the derivatives on your own. Again, we have A and B as matrices, two by two. And the C is here, actually calculated from A and B. We got C. And now we want to calculate the gradient of C with respect to A. And you don't have to do any derivatives on your own, but by inserting these lines. With gradient tape, watch A, you can actually automatically calculate C, D, A, just by calling tape.gradientCA.
And another important feature of TensorFlow that's really used by any other library in the Keras ecosystem is about deployment. It can be deployed anywhere for a model that implemented with TensorFlow. For example, it can be deployed on servers with TensorFlow Extended. And it can be deployed on single-chip machines like Edge Devices with TensorFlow Lite, and also deploy on any web pages with tf.js. And moreover, TensorFlow is really about performance and scalability. So it runs on GPUs and TPUs for acceleration of all those medical operations on tensors. It also scales up to multiple servers with multiple GPUs and TPUs to make the training of the model really fast, and make the prediction for the model really fast, and deployment of the model really fast. And that's about TensorFlow. It's a very powerful mission for the Keras ecosystem.
But how do we really leverage the power of TensorFlow? As we saw, the API of TensorFlow is very low-level, consists of a lot of mathematical operations. You don't really want to implement a whole lot of deep learning solutions with all those mathematical operations, because each deep learning solution may involve hundreds of those mathematical operations. You don't want to write each one of them in your code on your own.
2. Keras: High-Level API for TensorFlow
Keras is built on top of TensorFlow and provides high-level APIs that simplify deep learning. You can easily add layers to a sequential model and specify the number of neurons and activation functions. Loss calculations and training loops are handled automatically. Keras supports a wide range of tasks, from standard usage to advanced techniques like GANs and custom layers. For more complex scenarios, you can write custom metrics and losses, or even implement your own optimization algorithms using TensorFlow's low-level API.
So that's why we're going to go to the second member of the Keras, a radically productive deep learning. So for this one, it has actually built on top of TensorFlow and wrapping the TensorFlow low-level APIs into the high-level APIs, which are really simple to use.
We can see a very simple example code snippet here. We just initialize a sequential model, which is a type of model we're going to implement in Keras. And you can just keep adding those layers to the sequential model. Like here, we add a dense layer with 32 neurons, or units, in it, and activation function equal to Relu, and another dense layer to it. So then we got a model with two dense layers.
It's very simple to implement, and you don't really care about what mathematical operations are actually behind those dense layers, although it's actually matrix multiplication and additions, but you don't really need to write them on your own. You just use dense layer, and with a number of units. And also, you don't need to calculate the loss on your own. You just pass it as a string, categorical cross entropy. You don't do any calculations, but only a string.
This loss is actually for the classification task. And the model offset, you just passed in the training data. You don't need to write any loop on your own, like looping through 20 epochs. But you only pass in the data, and specify the epoch as 20. And then you start to do the predictions with the testing data. It's really simple to learn.
But despite the simplicity, it's capable of a lot of things. It's capable of everything supported by the TensorFlow low-level API. And you only need to learn what you need. We don't want the user to learn everything upfront that's quite a large learning curve. They start with a simple example like what we just showed before as a standard usage. You can use Sequential API, Function API, and Build and Layers.
But if you are aiming for something more, for example, you want to use TensorBoard and early stopping or saving the model to the disk with check pointing as you're training them, you can just pass a bunch of callback functions to the model. And it's really simple to do. But if you want something even more, like the GANS model or curriculum learning, and then you need to write some custom layers or custom metrics and custom losses, those are also very easy to implement just by extending the base classes in Keras.
But there are even more harder use cases, like learning to learn or you want to implement a new type of optimization algorithm, in that case, you will have to write your own training loop with the gradient tape operations. And with that, you are gaining full freedom of using anything supported with TensorFlow in Keras. So this is the logic of the API design of Keras.
3. Workflow and Keras Tuner
You only learn what you need. The workflow consists of three steps and a loop: training the model, evaluating the model, and making changes to the model based on the evaluation results. The tedious manual work of hyperparameter tuning should be automated. Introducing Keras Tuner, an automated hyper-parameter tuning tool built on Keras. It's simple to use and only requires minor modifications to the code.
You only learn what you need. And after we know how to use Keras to build deep learning models, let's see a typical workflow of a machine learning engineer. So the workflow consists of three steps and a loop. The first step is here, you need to train a model with model.fit with the training data. And the second step is to evaluate the model. And just to evaluate it with validation data, like how much accuracy it can get for our classification tests. And then you will see whether the accuracy is good or not.
If it is not good, you probably want to change something about the model. Those are called hyperparameters. The hyperparameter can be the number of layers or the number of units in the advanced layer or the learning rate. After changing, you need to build a model again and train it again with the training data, which is in step one. Then we go to step two to observe the performance. And so we go through this loop again and again until we reach somewhere you've got a satisfiable accuracy. Like, for example, over 90%, you feel it's good enough for the deployment, you stop the loop and deploy the model.
But in our opinion, the tedious manual work should be automated. We are all developers. We all develop solutions to automate everything we can to save our time. So that's why we developed Keras Tuner, the third family member of Keras ecosystem. It's an automated hyper-parameter tuning. It's very simple to use. It's built on Keras and only requires minor modifications to the code. Again, this is the code example we just showed before how we use Keras. We have a sequential model we put in the layers, like the dense layer here with 32 units and 10 units. But now we probably don't think that 32 is a very good number for the number of units in the dense layer. We want to find that automatically what's the best value for the number of units in this dense layer. So we only need to change this one line into something that looks like this. We just have a HP instance hyper-parameter. We pass the name of the hyper-parameter and a mean value and a max value and the granularity of the hyper-parameter. It's very intuitive, very simple to modify the existing code of Keras. And then you start the search by initializing a tuner.
4. Automating the Loop with AutoKeras
Here we use random search, which is a very simple search algorithm, of course. But we are having something better in Keras Tuner, like Bayesian optimization or hyperband. You can also use them. So now the loop is automated. We want them to directly have the solution and directly run the models. But how to use machine learning today is very different. We really want to reduce the learning curve of using machine learning. That's why we go to the fourth member of the family, which is called AutoKeras, an AutoML library for deep learning, to reduce the learning curve of really adopting machine learning in the real world applications. So let's see a very simple use case, as simple as three lines of code, to build a machine learning solution. And it is not requiring any machine learning background, actually, in this use case.
Here we use random search, which is a very simple search algorithm, of course. But we are having something better in Keras Tuner, like Bayesian optimization or hyperband. You can also use them.
Then you start to search by passing in the x train and y train as the training data and specified epochs and validation data. This is very simple to using the fit function of the model in Keras library. So now the loop is automated. You don't have to manually go through this loop again and again. And what we are thinking now is whether we can push this further to further automate this process. So we don't want the user even to be aware that the existence of this loop. We want them to directly have the solution and directly run the models.
So once Andrew Ng said AI is the new electricity, we all believe that. But now how we are using AI is very different from how we are using electricity. For example, how we are using electricity today is like when your phone battery is dead, you just plug it in your wall. I think everyone can do this. Everyone knows how to do this. But how to use machine learning today is very different. If you want to build a machine learning solution, you have to read a lot of textbooks and go through some online tutorials or even take some online courses in order to understand the algorithm behind those machine learning solutions. And by understanding those algorithms, you can start to know which model is best for your application. And then you can start to use those libraries to implement your machine learning solution. It's really hard to use. So we really want to reduce the learning curve of using machine learning.
And yeah, so that's why we go to the fourth member of the family, which is called AutoKeras, an AutoML library for deep learning, to reduce the learning curve of really adopting machine learning in the real world applications. So let's see a very simple use case, as simple as three lines of code, to build a machine learning solution. And it is not requiring any machine learning background, actually, in this use case. As you can see, we import AutoKeras as AK. And we initialize the image classifier, just for image classification tasks. And then you can call the fit function by passing in x and y. And no other arguments are specified here. You just throw in the training data. And then you can start the prediction by passing in the testing data.
5. AutoKeras Features and Deployment
AutoKeras supports all the Keras arguments, including callback functions, tensor board, and checkpointing. You can specify the number of epochs or let AutoKeras tune it automatically. The models can be exported as Keras models and deployed anywhere supported by TensorFlow.
It's fairly simple to use. And there are also some nice features about. First one is here, you're supporting all the Keras tumor arguments here in image classifier. For example, you can limit the size of the model we are trying to give you so that you can deploy it on an edge device with limited memory space. And for the fit and predict function, we are actually supporting all the Keras arguments. So it means you can pass callback functions to the fit function. And you can use tensor board, and checkpointing, early stopping, everything support about callbacks with Auto Keras. And you can specify the number of epochs here. But here, we didn't specify it in the example. It means you can also choose not to specify it if you don't know how much, how many loops you should go through the training loop. And we will tune in automatically for you. So it means we really require least amount of knowledge in order to use this library. And moreover, we have a nice feature of exporting the model. Here you call automodel.exportmodel, you actually got a Keras model. And that Keras model can be saved on disk for future usage and deployment. And remember, everything is built on TensorFlow, so these models can be deployed anywhere that is supported by TensorFlow.
6. AutoKeras: Tasks and Advanced Usage
AutoKeras supports various tasks, including image classification, regression, and more. It also handles complex scenarios like multi-model data and multi-task learning. For example, it can predict the price and occupancy of a house using both image and structure data. AutoKeras provides a simple interface, AutoModel, for specifying inputs and outputs. Advanced users can specify the search space for the model architecture using the functional API of Keras. They can connect different blocks, such as ResNet and ExceptionNet, and specify the merging and classification methods. AutoKeras supports different versions of ResNet and provides various other arguments for customization.
We're not only supporting image classifications. We're actually supporting six tasks in total, image classification, image regression, and also the same for task data and structure on classification and regression tasks. And more tasks to become are coming soon like object detection and image segmentation and time series forecasting. So you can expect that.
And besides those simple use cases, typical use cases, we are actually supporting some more complicated use cases like multi-model data and multi-task. This is closer to the real-world use case scenarios. For example, the image data can be a picture of a house and the structure data can be the attributes, some attributes of that house. For example, the total area of the house and the floor plans of the house. How many floors does it have? And the longitude or the latitude of the house where it's located. And in putting these information into the model, we want to do a regression, like predict the price of the house, and we want to do a classification of how many people should live in the house. And this scenario is actually supported by AutoKeras like this.
Again, it's very simple. Instead of using image classification, we're using another interface called AutoModel and you can pass the inputs and outputs to it. The inputs are just as shown in the figure in the previous slide. It's like an image input, a structure data input, and the output is just a regression head and classification head, very simple, they're intuitive to use. And you also call the fit function, but here it's multiple model data, so we are passing a list of X, the images and the structure data. And for multitasking, we are passing the regression targets and classification targets here. And that's for the multi-model and multitask.
And for advanced users, they may already know like what type of model is best for their solution, but they are not knowing all the details of every hyperparameter, so they want to roughly specify the search space, like the model should look like this, but without much details. So for example, the image data should use ResNet and ExceptionNet all together and merge the output together. And for structure data, we want to use multi-layer Perceptron and merge all of them together and do the regression and classification. So they should do something like this. It is exactly the same as the functional API of Keras. You can refer to the Kera functional API tutorials and learn it. But the idea is just connecting these blocks. ResNet block, ExceptionNet block, and the merge block, and classification how to regress and how you connect them together with this code. And notably, we're passing an argument here, which is version equal to v2. That means we will only search the v2 ResNet here in this block. But if you don't know which version is the best, you can choose not to pass it and leave it blank and we'll tune it automatically for you. And there are a whole lot of other arguments that are supported in the ResNet block, also other blocks.
7. Keras and TensorFlow Features
We support neural network blocks like ResNet and ExceptionNet, as well as preprocessing blocks like normalization, categorical encoding, text factorization, and image augmentation. AutoKeras is an AutoML library for deep learning that allows you to implement simple solutions with just three lines of code. It supports multi-model data and multitasking, and is built on Keras TuneR for automated hyperparameter tuning. Keras is a productive deep learning solution library that is built on TensorFlow, allowing for deployment in various environments and scaling up to multiple servers and accelerators. We acknowledge Datalab from Texas A&M University and the Google Keras team for their support. Thank you to everyone for attending the talk.
And we are not only supporting neural network blocks like ResNet and ExceptionNet, we're also supporting some preprocessing blocks like normalization, categorical encoding, or text factorization as well, and image augmentation. So you can connect them all together to build end-to-end solution.
Yeah, and let's have a review of what we talked about today. The first thing is about the last thing we talked about is AutoKeras, AutoML library for deep learning. You can implement a very simple solution with three lines of code. And we're also supporting multi-model data and multitasking. And it has built on Keras TuneR, which is very simple to use automated hyper-family tuning library which is built on Keras. And with minor modification to the existing Keras code you can do the hyper-family tuning. And Keras is a radical productive deep learning solution library. Again, it's very simple to use and you don't need to learn everything upfront but to learn gradually as you are having more complicated use cases. Everything here are built on TensorFlow, a very powerful foundation. You can deploy the model in various environments and the scale of the model up to multiple servers, multiple GPU and TPUs to accelerate the training. And finally, I would like to acknowledge Datalab from Texas A&M University and Google Keras team for supporting the project about Keras. And thank you everyone for attending the talk. Thank you.
It's really great that you also covered what else inside of Keras and TensorFlow, right? Because I have a feeling that sometimes people just forget that it's not only optimizers and layers, right? So there's many things that you can be using in your projects.
Yes, yes. We actually cover a lot of tools and a lot of people only know Keras. So if they try out other tools in the Keras community, it will be much helpful for their work.
Yeah, yeah. And I also believe that, you know, it's almost like there was a discoverability use case, right? Once somebody started using one tool, they'd be like, hey, maybe there's something else inside my books, right? And it does definitely benefit the entire ecosystem, right? To pick up, like, new things.
Yes. Yeah, cool. So I have a couple of questions. So first question is coming from Didu. I hope I'm pronouncing it correctly. Hi, Feng. What was one of the main challenges of making Keras and deep learning in general accessible to developers and lowering the knowledge barrier? This is like not to auto Keras, but I guess like more broader question, basically, to you.
Yes. So currently, I believe it's already kind of very accessible to many of the developers in the community.
8. Challenges for Beginners and Resources
Beginners face challenges due to limited background in math, statistics, and programming. Starting with easier projects like AutoKeras or taking beginner-level courses can be helpful. The TensorFlow and AutoKeras websites provide tutorials and examples. Francois shares examples on Twitter, and open source contributions are encouraged.
And, but the main challenge is still for beginners. For example, they have not very much mathematical background or statistics background or even limited programming experiences. In that way, I think it's still might be harder for them to get started. So even with the examples or documentation on the website. So in this way, I believe it will be more helpful for them to start with like either a easier project like autocarys or for them to take a more beginner level course in order to start. I think that's the only way maybe.
Nice, nice. And also the default TensorFlow website also has like many tutorials, right? The same goes to autocarys, if people can just click through right in the browser and get some results, so definitely good strategy. Yeah, and one more thing. There's also a Keras website, keras.io, that people can also check a lot of examples from there. Yeah, yeah, that's actually a good point that you're bringing this up, because as far as I remember, Francois was also like resharing quite a bunch of things like on Twitter. So right now if somebody has like a really cool example for keras or maybe how to use autocarys for this matter, they can also submit it like an open source, right, and this is gonna be accepted and maybe somebody gonna get the documentation famous, right? Yes. Nice.
Using TensorFlow and Keras in the Research Domain
The popularity of TensorFlow and Keras in the research domain depends on the specific research area. While deep learning researchers often require more flexibility and face a learning curve when using TensorFlow and Keras, efforts are being made to address these challenges. Eager Execution in TensorFlow provides more flexibility and allows researchers to write Python functions and incorporate them into the execution graph. Keras does not officially support ONIX, but there are third-party tools available for exporting Keras models to ONIX. In terms of optimizing the architecture of neural networks, Keras includes both pre-trained models and models without pre-trained weights. The default strategy in AutoKeras is to explore a large search space by starting with known good models and then fine-tuning hyperparameters.
Okay, so the next question is coming from Sanchit, and this user is asking like, hey, what is the strategy to make a TensorFlow slash Keras more popular for research domain? So I guess there's like this opinion, and we're sure if it's like backed up because I've seen like a different numbers to support this one or to reject it, said there's like a bunch of people in research that use not TensorFlow, but like other frameworks. Is there like anything that you, like let's say when you're developing like auto keras, right, that you do in order to target research community, or how do you feel is Keras TensorFlow for research or not so much, right? What is your opinion?
It depends on what the research area is. Like if it says a research area not other than the deep learning researchers, then people can also easily use Keras and TensorFlow since they're usually use the most popular models which are easily supported in TensorFlow or Keras. And, but for deep learning researchers, they usually do something crazy about tweaking the models to their own needs. For this flexibility is, I have to admit there are still some learning curves for them to get started with TensorFlow and Keras, but we are working hard on that. And that's definitely one of our highest priority of the team, and so currently, we are supporting Eager Execution. So you can have a kind of a similar effect as using Python, you can write Python functions and make it part of a TensorFlow operation and make it part of the execution graph. So that's also give a lot of flexibility to the research community.
Yeah, it's definitely a good point, right? Because I guess TensorFlow 1.X, right, or Keras before that, was also very static on the graph. And now, this Eager Execution or Eager by default from 2.X, this is very simple. And what you showed also in your example is a gradient tape, you can go very flexible. And I think, Francois, again, sharing many examples how you can customize your models and everything from distribution and going into handling data inputs that are already handled for you. And as a researcher, you do need to handle everything. Because sometimes, when I read also PyTorch code, I have a feeling that people, I mean, it is flexible, but it also has a cost, right? A price to pay that you need to handle those things on your own, right?
Cool. Another question is coming from Walter. And he's asking, hey, is Keras also targeting ONIX? Is there like a support? But it feels like, for me, that getting things working with ONIX is kind of hit or miss. Currently, we are not officially supporting it with any of the developers from Google. But we are relying on the open source community to support it. I believe there are some third-party tools, just for supporting how you can export the Keras model to ONIX model.
Another question is coming from Bernhard. Bernhard actually had yesterday lightning talk on AutoML. And he's asking today, like, hey, how does Keras optimize the architecture of the neural net? Or does it just find the best matching pre-trained network? Both are included. Both pre-trained model and models without pre-trained weights are included. We are trying to explore a large search space by starting the search with some warm startups. Like, we already know some good models, like ResNet and EfficientNet with pre-trained weights and some smaller vanilla convolutions. We just start the search with several good models we already know. Then we will start exploiting the details of the hyperparameters, like the optimizer and learning rate. And that's the default strategy of AutoKeras right now. I believe it's most suitable for most of the use cases, but you can always change other strategies like random search, hyperband and Bayesian optimization.
Customizing Models and Time Series Forecasting
AutoKeras allows users to specify the block structure and the depth and width of the network. The search space is limited, but it includes the most popular models and their hyperparameters. Users can configure their own models based on the available options. Additional ideas and issues can be shared on AutoKeras GitHub. A basic version of time series forecasting with AutoKeras is expected to be available by the end of the year, with full support for categorical and numerical data.
I believe it's most suitable for most of the use cases, but you can always change other strategies like random search, hyperband and Bayesian optimization.
Maybe just if I follow up from my side on this question, let's say like if you do, I don't know, like ResNet, right, or Inception, there's like some particular blocks, right, of the network that can't be like reused, like all across the board, right. When you do your own network construction, right, do you kind of reuse those blocks and after it's more like about Skip Connection, right, and architecture? Or you're also giving, you know, enough freedom, right, to also design like what block structure you're gonna use, right? Like how deep you go like in your optimizations or how wide, basically? The user can specify that. But the search space is still kind of limited, not infinite. So we are including the most, our hyperparameters of all those popular models inside the search space. But for ResNet, we're not like having infinite number of ResNet, but only like all the combinations of the hyperparameters will consist of like about 100 different ResNet models. And we believe that should be good enough for a user to search and for them to configure their own.
Yeah, nice, nice. It's very good. And in general, I guess if somebody has any additional ideas, they can still create issues like an AutoKeras in GitHub, right? And after you can always reuse them and see like what's happening. Maybe a last short question from Miguel. Miguel is asking like, hey, when can we expect possibility for a time series for a casting with AutoKeras? We hopefully, we will have a basic version done by the end of this year. Currently, actually, it does usable in the latest release but we didn't put it into the documentation because it's not stable enough and it doesn't support categorical data. And by the end of this year, we expect the full version that supports both categorical data and numerical data and the time series for casting. Nice, amazing. Thank you again for answering all those questions but also for delivering this talk for us. It was pleasure listening to you.
Comments