Tuesday, April 6, 2021

Four Key Stages of The Machine Learning Process

These four stages is defined by Emmanuel Ameisen in his recent book Building Machine Learning Powered Applications. As I think it is an important piece, I created a process diagram above and note down few important points for each stage. You can considered this is a study note.

1. Identifying the Right ML Approach

The best approach for a given problem (product goal) will depends on success criteria, data availability, task complexity and model choice.

2. Building an Initial Prototype

Start by building an end-to-end prototype before working on a model which aim to tackle the product goal with no ML involved and will allow you to determine how to best apply ML.

3. Iterating on Models

If you need ML, start gathering dataset, train a model and evaluate it shortcomings. The goal of this stage is to repeatedly alternate between error analysis and implementation.

4. Deployment & Monitoring

Once a model shows good performance, you should pick an adequate deployment option. Once deployed, models often fail in unexpected ways. The last two chapters of the book will cover methods to mitigate and monitor model errors.

Side Note

I added an arrow labelled "New product goal, Revised product goal" to the process diagram. Based on my experience, software products evolve, it will not end there after the ML solution went live. Hence, it is likely that the existing product goal will be revised or new product goal being inspired or discovered. Then, the cycle start from stage 1. Don't you think so?

Friday, April 2, 2021

Showcase Your Widget with Flutter Widgets Explorer

Start from now, you can use Flutter Widgets Explorer as a platform to showcase your widget with README, codes and licensing information. The Flutter Widgets Explorer supports Android devices at the moment and will support Web in a week or two (Updated on 16 April 2021: The web version of the Flutter Widgets Explorer just went live @ fluwix.com). 

That's made possible by the Showcase View widget, let's me show you how it looks:

If the default Read Me, Code and License tabs are not enough for you, the Showcase View widget support additional tabs too, please see the following image:

Does it sound and look interesting? You are invited to fork the fluwix github repo, add your code and send me pull request. The key takeaways are you can showcase your code live in an Android app, Fluwix.com and embedded HTML (as iframe) in your blog post. We will take care the hassles of managing the deployment, production and marketing for you. If you're interested, please submit your idea of showcase.

Are you facing any problem with your Flutter development? Please answer the 3 questions Flutter Development Survey as we might have the solution to your problem. 

By the way, you can install the Fluwix (formerly Flutter Widgets Explorer) app to your android phone by clicking on the following image link:

Get it on Google Play
Kindly raise an issue if you have any problem running the Fluwix on your mobile or web.

I think the best way to find out how Flutter Multi-modules works is create the module and try it out yourself. If you don't have any idea, I'm looking for contributors to help on migrate the existing showcases to Flutter modules. So far 5 completed, 9 more to go. If you are interested to help, feel free to look into the module migration guide. If you're still not turn down by the long list of steps and willing to give me a hand, great! :), kindly open an issue in the Github issues and tell me which showcase you are interested to migrate (Updated on 16 April 2021: I completed all migration works myself, thanks to module_starter automated most of the manual works). 

Lastly, If you are interested to reuse the source code of the screen, please check out the showcase_view branch of the git repository hosted at https://github.com/limcheekin/fluwix. Feel free to fork the repository and send me pull request.

As usual, I'd love to hear from you. :)

Wednesday, March 31, 2021

Flutter Navigation: flutter_modular or stacked?

The current way of Flutter Widgets Explorer using switch statement to construct the main listing screen and navigation no longer sustainable as I foreseen the number of showcases will be double or triple in the coming months.

Hence, I decided to look into new solution. First, I come across an article shared about Flutter Navigation 2.0. In my opinion, it is too complex, we need better abstraction to make it usable to developers. I search again and finally nailed down to two alternatives: flutter_modular and stacked.

Let's look at simple code metrics (line of codes) for both packages:

















It is obvious that flutter_modular is the winner here. It has less boilerplate code and code generation is not required. For stacked, it still has more line of codes compared to flutter_modular after excluding the generated app.router.dart and app.locator.dart. Also, flutter_modular using Navigation 2.0 and stacked still using Navigation 1.0 if I'm not wrong (Correct me if I'm wrong).

Lastly, there's one pending issue for Flutter Widgets Explorer to adopt flutter_modular as it's navigation library, the default back button is missing, I opened an issue that still pending for response at the time of writing.

If you interested to dig into the code, feel free to look into the github repo for flutter_modular and stacked implementation.

Happy coding! :)

Tuesday, March 23, 2021

Deploy Serverless Machine Learning Models to AWS Lambda

I just completed the Udemy course with the same title of the blog post.

The course cover three machine learning examples using different library:

  1. scikit-learn: Using regression model from scikit-learn trained on California housing dataset for house price prediction.
  2. spacy: Using a small English model from spaCy NLP framework for named entity recognition.
  3. keras: Using ResNet50 computer vision deep learning model from Keras framework to create for image recognition.

Let's me tell you the following value-added changes of my code from the original source code from the course:

  • The examples are using Python 3.8 instead of Python 3.6 in the course and latest version of libraries except the scikit-learn example using earlier version of scikit-learn to align with m2cgen which has the possibility to convert scikit-learn model to native code and C code running in the microcontroller with emlearn.
  • To deploy all examples. you only need git, no other installations are required. All examples are setup with continuous deployment pipeline using Github Actions. The following diagram shows how it works from the high-level:
  1. Developer update changes to repository by sending a git push command. 
  2. The git push command will trigger the Github Actions workflow which run the serverless deploy command based on configurations in serverless.yml file. 
  3. The CloudFormation stack consists of API Gateway, AWS Lambda, S3, ECR, etc. will be created on AWS.
After you forked my repository, you just need to add AWS_KEY and AWS_SECRET to Repository secrets of Settings/Secrets of your github repo like the following image:
Then, you can deploy all examples to AWS lambda with a git push command.

  • All examples are setup with "warm start" and request throttling limit to 1 to protect your account and your wallet (You don't want to have surprises in your monthly credit card bill for demo projects, right?)
  • All examples have a last step "Test Lambda functions" to verify the public API is working post-deployment.
  • Spacy and keras example are deploy using Docker container image to AWS Lambda. Thanks to Jan Bauer published the blog post Using container images to run TensorFlow models in AWS Lambda, timing is just right on helping me to get the keras example working.
  • For keras example, image uploaded directly to Lambda endpoint and store as temp file instead of upload to S3 bucket.
  • Code of each example is located in its own branch.

Please take note of the storage cost of S3 and Elastic Container Registry (ECR), make sure you clean up unnecessary files and Docker image files there.

Lastly, if you look for someone on deploying your machine learning model to AWS lambda, I think I can help here. :)

Oh yeah, here is the github repo URL https://github.com/limcheekin/serverless-ml if you missed it.

I think the scope is broad enough for now, let's go deep.

Stay tuned to the next!

Monday, March 22, 2021

Flutter Multi-modules Support

I wrote this article to inform Flutter developers for a lesser known feature of Flutter: Multi-modules support in a Flutter project. Thanks for inspiration from an article A Flutter BLoC + Clean Architecture journey to release the #1st Idean Flutter app published on Medium.com. It mentioned about “Dart modules”, I not sure whether we are referring to the same thing here.

After gone through the article above, I perform a google search for Flutter module and I found many articles and videos on how to create modular Flutter project, or how to structure Flutter code in modular way, and a library known as flutter_modular. But I’m looking for “real” modules that supported by Flutter and IDEs to define a physical boundary among modules, not a logical one defined by developers. It is an “aha!” moment, out of no way I am thinking of typing flutter create –help command in my terminal window. From the list of options, I found the following option like what I am looking for.

Then, I proceed to flutter.dev website to find out more information about the -t option, not much information found besides a description similar to the above. Hence, I decided to create a Flutter project to test it out. In the flutter project directory, I’m creating two modules such as nested_list and tab_buttons using the following command:

flutter create -t module <module_name>

The following is directory structure of the Flutter project, you can see that the nested_list and tab_buttons module is outside the lib directory (All Flutter code need to be located in the lib directory normally).

The following is the advantages of the “real” Flutter module besides modular structure:

  • It has it’s own pubspec.yaml file, you can manage assets, dependencies and other stuff on module-basis.
  • It can have it main.dart, you can run the code of a module independent from project and other modules.
  • It can have it own test directory, you can write tests to test code of the module.
  • A Flutter project can have mix of non-null safety and null safety packages which segregated by modules.
  • You can start null safety migration module by module without blocking the release cycle. Flutter Widgets Explorer will adopt this approach.

Once the module is ready, you can link the module to the project by specify the following dependencies  configuration in the pubspec.yaml file:

The Flutter project is working in my mobile phone and Google Chrome with the following command:

flutter run -d chrome

Please check out the following github repo and test it out yourself:

https://github.com/limcheekin/flutter-modules

Thanks for reading, I hope the write ups is helpful to you, hear from you soon! :)