<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Masaki Kozuki on Medium]]></title>
        <description><![CDATA[Stories by Masaki Kozuki on Medium]]></description>
        <link>https://medium.com/@crcrpar?source=rss-c693456dd6af------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jnBeG5nPrCaLwpzk02n6Rw.jpeg</url>
            <title>Stories by Masaki Kozuki on Medium</title>
            <link>https://medium.com/@crcrpar?source=rss-c693456dd6af------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 14:59:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@crcrpar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Parallel Hyperparameter Tuning With Optuna and Kubeflow Pipelines]]></title>
            <link>https://medium.com/optuna/parallel-hyperparameter-tuning-with-optuna-and-kubeflow-pipelines-4ef05ce614ae?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ef05ce614ae</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[automl]]></category>
            <category><![CDATA[optuna]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Fri, 06 Nov 2020 02:31:48 GMT</pubDate>
            <atom:updated>2024-08-28T13:52:30.199Z</atom:updated>
            <content:encoded><![CDATA[<h3>Parallel Hyperparameter Tuning with Optuna and Kubeflow Pipelines</h3><p>This entry is a translation of the Japanese-language <a href="https://lab.mo-t.com/blog/optuna-kfp-hyperparameter-tuning">blog post</a> originally authored by Mr. Masao Tsukiyama of Mobility Technologies Co., Ltd. The Optuna community would like to thank Mr. Tsukiyama for permitting us to post this translation.<br>Disclaimer: All the slides and videos are in Japanese language.</p><h3>Introduction</h3><p>Hi there. This is Masao Tsukiyama of ML engineering group 1 of AI technology development department of Mobility Technologies (MoT).</p><p>The other day, I tuned hyperparameters in parallel with Optuna and Kubeflow Pipeline (KFP) and epitomized it into a slide for an internal seminar and published the slides, which got several responses.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2FnduvOp24VPV1QF&amp;display_name=SlideShare&amp;url=https%3A%2F%2Fwww.slideshare.net%2FMasaoTsukiyama%2Foptuna-on-kubeflow-pipeline&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Foptunatsukiyamapublic20200430-200430104614-thumbnail-4.jpg%3Fcb%3D1589459983&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/bef7314e87d8e8742bf306c8cfa4010c/href">https://medium.com/media/bef7314e87d8e8742bf306c8cfa4010c/href</a></iframe><p>The slide was noticed by an Optuna maintainer, and they asked me to write a blog about it. There are some duplicated contents with the above slides, so let me walk you through the below items with some figures and snippets</p><ul><li>Optuna and KFP use case</li><li>introduction and tutorial of Optuna and KFP</li><li>Optuna’s usability and contribution to our project</li><li>tips for integration into production.</li></ul><h3>Use Case Definition</h3><p>When it comes to hyperparameter tuning, you may think of the hyperparameters of machine learning and deep learning, such as the number of layers of your deep neural network.</p><p>However, we wanted to optimize the parameters of reinforcement learning models which propose the optimal route for one of our products called Passenger Search Navigation.</p><h3>What is “Passenger Search Navigation”?</h3><p>We, at MoT, provide a machine learning based service named Passenger Search Navigation (Japanese name is “お客様探索ナビ”) with taxi drivers using taxi distribution service “GO”. This service helps the drivers find riders when they are not waiting for ones at stations, aiming at enabling new hires at taxi companies and drivers who are not familiar with the area to make more money than the average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8A_nNiZmCUA3uwglj0etw.jpeg" /></figure><h3>How Machine Learning Plays a Role?</h3><p>This section explains how Passenger Search Navigation recommends routes to drivers.</p><p>To suggest a route to a driver, we implement the following steps</p><ol><li>Create machine learning models using stats, such as the number of rides, and predict the number of ride requests in the next 30 minutes on each road (demand).</li><li>Create other machine learning models that take the same stats and predict the number of taxis that will be on the road in 30 minutes on each road (supply).</li><li>Run inference of the both models every 15 minutes to continually update the predicted demand and supply.</li><li>Recommend a route with the predicted demand and supply with reinforcement learning.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*epVJiMPP4uVKdHUit9wwSg.jpeg" /></figure><h3>Reference</h3><p>Should you be interested in the detailed algorithm, there are some materials in Japanese.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2F5fgW3UDGExH9QY&amp;display_name=SlideShare&amp;url=https%3A%2F%2Fwww.slideshare.net%2Fdena_tech%2Fdena-techcon-2019-132196217&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Fmisocial-190218070258-thumbnail-4.jpg%3Fcb%3D1550473475&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9652a20900e4ad81c786621aaafb2e4/href">https://medium.com/media/e9652a20900e4ad81c786621aaafb2e4/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZy8S4MXxuRA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZy8S4MXxuRA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZy8S4MXxuRA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0925d66e94926370a50e668b41ed22c/href">https://medium.com/media/b0925d66e94926370a50e668b41ed22c/href</a></iframe><p>Also, I would highly recommend the below materials for those who are interested in the whole architecture and MLOps of our service.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2FwMwNQ6bgWTWyYo&amp;display_name=SlideShare&amp;url=https%3A%2F%2Fwww.slideshare.net%2Fdena_tech%2Fmov-mlops&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Fmovsmachinelearningmlops-200316055433-thumbnail-4.jpg%3Fcb%3D1584579915&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/07cc883de703a1429ca46fcc67f26619/href">https://medium.com/media/07cc883de703a1429ca46fcc67f26619/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FmH3XlaX04IA&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmH3XlaX04IA&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FmH3XlaX04IA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/194b0e9b041c117b5247aa7d1d3b692c/href">https://medium.com/media/194b0e9b041c117b5247aa7d1d3b692c/href</a></iframe><h3>Hyperparameters of Value Iterator</h3><p>In the above reinforcement learning, there exists a component called Value Iterator. As you know, this Value Iterator has some amount of hyperparameters and these hyperparameters have some effects on the recommended route as well as the predicted demand and supply.</p><p>Furthermore, the predicted route affects the profit in the simulation and the profit of each driver. This is the reason we want to tune these hyperparameters of Value Iterator.</p><p>To be exact, the situation was like this:</p><ul><li>Value Iterator component has a bunch of hyperparameters, however, we have not tuned them from Proof of Concept to the present.</li><li>Due to the nature of our Passenger Search Navigation, we need different models for different areas and the optimal hyperparameters would be different.</li><li>Also, optimal hyperparameters would be different in different timeframes.</li></ul><p>Given the above, we decided the following tuning requirements:</p><ul><li>The entire tuning process must be automated</li><li>Tuning can be executed with ease regularly or as necessary</li><li>It’s not too time-consuming</li><li>It’s not too compute-hungry; we have a limit on the server cost</li></ul><p>While there are various frameworks for hyperparameter tuning, we chose Optuna as it is popular and it looked easy to use with its intuitive interface.</p><h3>Simulation and Evaluation of Machine Learning Models</h3><p>As it’s related to why we adopted Kubeflow Pipeline (KFP) for parallel hyperparameter tuning, let me illustrate the simulation and evaluation of machine learning models in Passenger Search Navigation.</p><p>In Passenger Search Navigation, two machine learning models predict the demand and supply, and then the reinforcement learning model suggests a route from that demand and supply. To evaluate the suggested route, we have <strong>a simulator to see how much profit it will make</strong>.</p><p>We evaluate the route with how many rides occurred and when and where rides happened from the records of actual demand and supply.</p><p>The criterion of updating the machine learning models included minimizing the squared error and maximizing the simulated profit.</p><p>So, our tuning task would run the below repeatedly</p><ol><li>Update the hyperparameters of Value Iterator component</li><li>See the profit by running the simulator with the updated hyperparameters</li></ol><p>The duration of simulation is one week (seven days), though we have already composed a KFP pipeline to collect the data of seven days in parallel and run the simulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5C7ljMfEYuRO9EC_" /></figure><p>We chose KFP because it’s simple to automate the tuning and we can utilize this existing pipeline.</p><h3>Introduction and Tutorial of Optuna and KFP</h3><p>Let me briefly summarize Optuna and KFP for those who are not familiar with them.</p><h3>What is Optuna?</h3><p>Optuna is an open source hyperparameter optimization framework to automate hyperparameter search. It’s released in December 2018 and its stable version came out in January 2020. It’s implemented in Python, like other machine learning frameworks.</p><p>Features unique to Optuna listed up in <a href="http://optuna.org">the official page</a> are</p><ul><li>Parallelize hyperparameter searches over multiple threads or processes without modifying code</li><li>Automated search for optimal hyperparameters using Python conditionals, loops, and syntax</li><li>Efficiently search large spaces and prune unpromising trials for faster results</li></ul><p>In general, it’s designed to make it easy to implement distributed and parallelized tuning.</p><h3>Tutorial of Optuna</h3><p>The below is copied from <a href="https://optuna.readthedocs.io/en/stable/tutorial/001_first.html#first">the official tutorial</a> that you can download in a Python script or Jupyter Notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c3f37184d69266abb0470520922f0f9/href">https://medium.com/media/3c3f37184d69266abb0470520922f0f9/href</a></iframe><p>In Optuna, the whole tuning process is called Study and each evaluation of one set of hyperparameters is called Trial.</p><p>You define the process of the evaluation of each trial from sampling hyperparameters to return of the evaluated value. In the above snippet,</p><ul><li>create_study instantiates a new Study specifying direction=”minimize” / direction=”maximize” as the objective function is to be minimized/maximized.</li><li>study.optimize executes the tuning. The number of trials is 100.</li><li>The objective function samples the hyperparameter of x and evaluates the quadratic function.</li></ul><p>A Study object provides the following useful methods and attributes.</p><pre>study.best_params<br>&gt;&gt; {&#39;x&#39;: 1.9926578647650126}</pre><pre>study.best_trial<br>&gt;&gt; FrozenTrial(number=26, state=&lt;TrialState.COMPLETE: 1&gt;, params={‘x’: 1.9926578647650126}, value=5.390694980884334e-05, datetime_start=xx, datetime_complete=xx, trial_id=26)</pre><pre>study.trials<br>&gt;&gt; [FrozenTrial(number=0, …), …]</pre><p>The example we’ve looked at uses only one floating point values in linear space with suggest_float method, Trial provides the following methods for hyperparameter suggestion:</p><pre># Categorical<br>optimizer = trial.suggest_categorical(“optimizer”, [“MomentumSGD”, “Adam”])</pre><pre># Integer<br>num_layers = trial.suggest_int(“num_layers”, 1, 3)</pre><pre># Floating point values in linear space<br>dropout_rate = trial.suggest_float(“dropout_rate”, 0.0, 1.0)</pre><pre># Floating point values in logarithmic space<br>learning_rate = trial.suggest_float(“learning_rate”, 1e-5, 1e-2, log=True)</pre><pre># Floating point values in discrete linear space<br>drop_path_rate = trial.suggest_float(“drop_path_rate”, 0.0, 1.0, step=0.1)</pre><p>Other than Study and Trial, Optuna has the concept of Storage. As the name implies, Storage tracks the history of Study and its Trials, and there are several types available depending on the use case.</p><p><strong>InMemoryStorage</strong>:</p><ul><li>Default storage class</li><li>Claims Storage on the memory where tuning is running</li><li>Basically not tracking Trials for long</li><li>Faster than RDBStorage if you parallelize tuning in one unique instance</li></ul><p><strong>RDBStorage:</strong></p><ul><li>Claims storage in external RDB</li><li>MySQL, PostgreSQL, and SQLite is available</li><li>Best for distributed optimization as all Study and its Trials are recorded</li><li>Allows for stop and resume of Study</li></ul><p>In Optuna, you can specify the number of jobs with the argument of n_jobs to Study.optimize. We have only one Optuna job, but execute Trials in parallel with KFP and n_jobs, both options are feasible. However it turns out to be helpful to be able to reference the history of Study and Trials, and as sometimes we want to increase the number of trials, we set up MySQL server on GCP Cloud SQL and use RDBStorage.</p><h3>What is Kubeflow Pipeline (KFP)?</h3><p>Kubeflow including KFP is a framework developed by Google, and it provides enough tools to implement a whole cycle of machine learning projects on Kubernetes. As a side note, we did not use any other Kubeflow components other than KFP.</p><p>KFP is a workflow engine oriented to machine learning and is getting more and more popular these days, but we rarely see the use case of the other components.</p><p>There are other famous workflow engines like Apache Airflow and DigDag, though, KFP has some strong points as follows:</p><ul><li>A feature named “Experiment” allows for preparing a pipeline for each experiment and you can change input parameters and execute from its Web UI.</li><li>Visualization of inputs and outputs of every single pipeline task, enabling us to check the artifacts such as Jupyter Notebook and Confusion Matrix on the Web UI.</li><li>Easy comparison of experiments and their results, leading to easier comparison of parameters.</li></ul><p>KFP is built on top of Argo, an OSS workflow engine for machine learning, but KFP is more friendly as we can define pipelines with Python. In Passenger Search Navigation, we use KFP for R&amp;D things, e.g., simulation and experiments and Apache Airflow for operation things, e.g., machine learning models’ deployment pipeline and their inference pipelines.</p><p>Sometimes it’s better to use different tools for different phases.</p><h3>Parallel Hyperparameter Tuning Flow with Optuna and KFP</h3><p>So, here comes the result: the implementation and hyperparameter tuning of Passenger Search Navigation.</p><p>Let’s consider the implementation policy upon the above Optuna snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f3d20d2914dc9cdef8f03f7a900f46e/href">https://medium.com/media/5f3d20d2914dc9cdef8f03f7a900f46e/href</a></iframe><p>As it’s preliminary, tentatively set n_trials (the number of trials) as 100.</p><p>As the default optimization algorithm of Optuna is TPE and it’s sequential, too big n_jobs might harm the performance of TPE, therefore, n_jobs is 5 and 5 turned out not to be harmful.</p><p>So what we need to do in objective is collect the simulated profit after running the simulation using the suggested hyperparameters for Value Iterator component.</p><p>We’ve already implemented the simulation process as a KFP pipeline job and used the job for experiments and evaluation in the deployment pipeline.</p><p>The below figure illustrates how this flow is organized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hh8QEp713yaNHmLBS5RoBw.jpeg" /></figure><p>Of course, you can run Optuna locally, but it’s tedious to wait for the tuning to terminate after a couple of hours, so I implemented a KFP job to execute Optuna.</p><p>At first, a deployed Optuna job calls create_study to start a new tuning which is tied to MySQL server on Cloud SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpkcWo4hiho47fP7QaSFHA.jpeg" /></figure><p>As n_jobs is 5, study.optimize evaluates 5 trials in parallel. Each running trial runs a simulator job pipeline to KFP with the suggested hyperparameters for Value Iterator component before getting the simulated profit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvS-7TqSEYU_hCnCVsbg-Q.jpeg" /></figure><p>Each thread is waiting for its simulation to end. The above figure looks like the threads are synchronized though, actually each thread runs Trial independently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRVYkkMb7jgHybTTyfU8OQ.jpeg" /></figure><p>After the Trial finishes, store results to the storage and run the next trials. In the new trials, hyperparameters are suggested using the past records and these steps are repeated until the simulated profit gets converged.</p><p>Thanks to RDBStorage, if n_trials is not enough, we can resume this tuning with optuna.load_study.</p><h3>Codebase</h3><p>So far we’ve looked at how our fully automated tuning flow is implemented figuratively. Now I will show you the actual codebase.</p><h3>Deploy Optuna Job</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a5ade8fc7ae6ee5730ff1240776396/href">https://medium.com/media/00a5ade8fc7ae6ee5730ff1240776396/href</a></iframe><p>Let’s focus on the thing. The deployment of Optuna Job pipeline is implemented in wf.create_optuna_pipeline which will be explained soon. This method compiles the created pipeline and deploys it with wf.run_pipeline() to the KFP cluster.</p><h3>KFP Pipeline Function of Optuna Job</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91b6b878e62108fd7d9ae7547cd869a0/href">https://medium.com/media/91b6b878e62108fd7d9ae7547cd869a0/href</a></iframe><p>This is the implementation of wf.create_optuna_pipeline(). In KFP, we can implement pipeline functions with @kfp.dsl.pipeline decorator. By passing a Slack notification Operator to dsl.ExitHandler, we will be notified when the job terminates, whether it succeeds or not.</p><h3>KFP Operator of Optuna Job</h3><p>This Operator runs Optuna task is implemented as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbefaf0261f8f25b320958e3cbbfb33f/href">https://medium.com/media/dbefaf0261f8f25b320958e3cbbfb33f/href</a></iframe><p>create_optuna_op creates a Container Operator that runs Optuna Job. There’s one task per container, so we deploy the task to the KFP cluster specifying any Docker image. Note that we can specify Sidecar Container as Container Operator.</p><p>As our Optuna job uses RDBStorage (MySQL server on CloudSQL to be exact) GCP’s official container gcr.io/cloudsql-docker/gce-proxy is used. The process of tuning is encapsulated into the Image passed to this Operator.</p><h3>Tuning Execution with Optuna Job</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d058e6a56c70156971e209312e98bac/href">https://medium.com/media/4d058e6a56c70156971e209312e98bac/href</a></iframe><p>Containers initiated by the Operator first call this method according to the storage argument.</p><p>We pass settings[“study_storage”] but it’s a sting of the format of mysql+pymysql://{user}:{password}@localhost/{cloudsql_datasetname} (remember, we use MySQL). You can also have this connected to MySQL Server via CloudSQL Proxy of Sidecar.</p><p>load_if_exists argument enables you to resume the existing Study of the same ID on the Storage if `True`.</p><h3>The Objective Function</h3><p>Recap of our objective function</p><ol><li>Sample hyperparameters for Value Iterator component</li><li>Run simulation with the hyperparameters sampled above</li><li>Get and return the result (= profit) from the simulation</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1811f7af3f0aa9e952d3557c57102510/href">https://medium.com/media/1811f7af3f0aa9e952d3557c57102510/href</a></iframe><p>As we have multiple hyperparameters for different Distributions of the Value Iterator component, each of them are suggested by using getattr to specify the distribution and the domain after writing down distributions and search space for each hyperparameter to a config file.</p><p>Next, it checks if the number of correctly completed trials from Study is smaller than the specified number of trials. The waiting for simulation sometimes fails, so there is a workaround in case len(trials) doesn’t tell us the exact number of completed trials.</p><p>This kind of handling can be implemented with a callback function for Study.optimize. In the callback which takes Study and Trial as its inputs, check the number of completed trials and compare it with the maximum number of trials in order to decide whether to stop (Study.stop) or not.</p><p>run is a function that generates a simulation pipeline (Operators) and deploys it to the KFP cluster as already explained.</p><p>Finally, different from the deployment of Optuna Job, we need to wait for the simulation termination after run_pipeline before collecting, summarizing, and returning the simulated profit.</p><h3>Evaluation of Hyperparameter Tuning</h3><p>If the simulated profit converges, move on to the comparison of hyperparameters.</p><p>To compare the performance of the hyperparameters previously used and the hyperparameters tuned:</p><ul><li>Tune the hyperparameters for the fixed two machine learning models with the data of 2019/10/01–2019/10/7</li><li>To see that the tuned hyperparameters are not overfitting, evaluate the two sets of hyperparameters on the data of 2019/10/08–2019/02/29 by simulation</li><li>As to the demand and supply in the simulation, we use both the predicted values and statistical values. This can be the case for our production environment.</li></ul><p>From this comparison, we confirmed that the profit is raised by 1.4% and 2.2% by using the predicted values and statistical values, respectively.</p><p>Then we release the new set of hyperparameters to the production after having the quality assurance team confirm the proposed routes are valid.</p><p>So, in short, we can gain the profit increase using fully automated parallel tuning with Optuna better than or equal to the profit increase with the policy by our algorithm team. Note that the latter requires work and is not automated.</p><h3>Usability of Optuna</h3><p>As said previously, the tuning with Optuna brought more than the 2% gain to our drivers. The hyperparameters that are achieved are already live and suggesting routes to our drivers.</p><p>We have not been able to compare the profit of our drivers before and after the release, thus we are a bit sorry not to be able to say “our automated tuning gives our drivers joy”. A real world comparison is difficult as the profit and routes depend on season, timeframe, and luck.</p><p>So here are some thoughts of using Optuna in our product:</p><ol><li>Interface is intuitive and easy to parallelize and distribute</li><li>Easy to keep implementation simple because we can handle the objective function as a black box of taking hyperparameters as inputs and returns some value.<br>Thanks to this design, we were able to use Optuna without modifying our codebase of simulation and its execution as we just encapsulate Optuna specific logic into new functions.</li><li>SDK is useful<br>Most information we want can be accessed from Study and Trial, which make it easier to do some detailed processing in the objective function and post-analysis of tuning</li><li>Integrating Optuna into existing projects is not hard because of 1, 2, 3.</li><li>Customizability though we haven’t tried</li></ol><p>As the simulation is implemented as a KFP pipeline, our codebase deploys KFP jobs in a nested manner, making it a bit complicated.</p><p>We were looking for a better design initially, but chose this approach because we could understand the relationship between tuning and simulation.</p><p>In short, the design is easy to understand and we could move to implementing our logic quickly.</p><h3>Tips for Optuna in Production</h3><p>We had enough benefit from integrating parallel hyperparameter tuning into our product because</p><ul><li>we would create multiple models and each model has different optimal hyperparameters.</li><li>timeframes cause models to use different hyperparameters for better performance.</li></ul><p>As noted beforehand, since Optuna enabled us to handle the logistics that we want to tune as a block box, keeping existing smaller codebase is not difficult.</p><p>As our problem is not so common and we had enough resources, we spent the time to automate the tuning process. However, even if your problem is simple like wanting to run tuning on a few instances for experiments, I would say that you will enjoy the merit of Optuna.</p><p>So, whatever hyperparameters you are tuning, the general workflow will be as follows:</p><ul><li>you have some inputs like hyperparameters and some outputs that you want to optimize</li><li>If the number of hyperparameters are astronomic, starting from small portion of them would be good</li><li>Confirm that it is allowed to tune your hyperparameters.<br>Sometimes they include some that should not be tuned or tuning is meaningless.</li><li>Implement the objective function.<br>Keeping the relationship of this function and the experiment logic sparse is great.<br>e.g. Encapsulating it into KFP’s Experiments Pipeline<br>The only requirements are that the function takes some inputs and outputs something.</li><li>Choose the number of trials and run tuning<br>You can resume the study with RDBStorage, you can increment the number of trials like 100 -&gt; 150 -&gt; 200</li><li>Run experiments to check the performance the optimal hyperparameters Optuna finds<br>In our case, we ran simulations for the period that are not the target of tuning to see the gain.<br>For the case of machine learning model training, do tuning on validation accuracy or loss and see the test accuracy lastly.</li><li>Finally, decide whether to use that hyperparameters</li></ul><h3>Conclusion</h3><p>We integrated Optuna for the first time while we’ve used KFP for simulations.</p><p>To repeat, Optuna is good for its intuitive interface, good documentation, and its design that allows for simple implementation.</p><p>Since this problem would enjoy the benefit of re-tuning after some period, we automated the comparison experiment by scheduling a regular tuning pipeline.</p><p>Hope you get some takeaways by this post, thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ef05ce614ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optuna/parallel-hyperparameter-tuning-with-optuna-and-kubeflow-pipelines-4ef05ce614ae">Parallel Hyperparameter Tuning With Optuna and Kubeflow Pipelines</a> was originally published in <a href="https://medium.com/optuna">Optuna</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Implement Hyperband in Optuna]]></title>
            <link>https://medium.com/optuna/optuna-supports-hyperband-93b0cae1a137?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/93b0cae1a137</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automl]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Wed, 26 Feb 2020 05:27:44 GMT</pubDate>
            <atom:updated>2024-08-28T13:29:42.463Z</atom:updated>
            <content:encoded><![CDATA[<h3>How We Implement HyperBand in Optuna</h3><p><strong>UPDATE (2020/08/31)</strong>: The content would be somewhat outdated because we improved the algorithm and interface. See the details for the following five pull requests: <a href="https://github.com/optuna/optuna/pull/1138">optuna/optuna#1138</a>, <a href="https://github.com/optuna/optuna/pull/1141">optuna/optuna#1141</a>, <a href="https://github.com/optuna/optuna/pull/1171">optuna/optuna#1171</a>, <a href="https://github.com/optuna/optuna/pull/1188">optuna/optuna#1188</a>, <a href="https://github.com/optuna/optuna/pull/1196">optuna/optuna#1196</a>.</p><p><em>This post requires some familiarity with Optuna and targets those who are rather interested in software for Machine Learning and Deep Learning than ML and DL technologies and/or algorithms themselves. Also, I hope some of you feel like giving Optuna a try, or contributing to Optuna after you read this.</em></p><p>If you’re new to Optuna, here’s <a href="http://colab.research.google.com/github/optuna/optuna/blob/master/examples/quickstart.ipynb">the quickstart on colab</a>, <a href="https://medium.com/optuna/optuna-v1-86192cd09be5">v1 release announce post</a>! :)</p><h3>TL; DR</h3><ul><li>Sampler and Pruner of Optuna are loosely connected for modularity.</li><li>Optuna has <em>experimentally</em> supported Hyperband [4] now from <a href="https://github.com/optuna/optuna/releases/v1.1.0">v1.1.0</a>, one of the most popular and competitive hyperparameter optimization (HPO) algorithms.</li><li>Challenges in implementing Hyperband in Optuna is discussed in this post.</li><li>We resolved the challenges in a simple and beautiful manner.</li><li>We can use competitive hyperparameter optimization of Hyperband with ease. Feel free to try it now! Benchmark results are shown later.</li></ul><p>In the first section, I briefly introduce the structure/modules of Optuna. Then I’ll illustrate how pruning algorithms work with a naive algorithm. After that, Successive Halving, a popular HPO algorithm is introduced and its weak points are discussed. Last, Hyperband is introduced and how we implemented is described.</p><h3>Under the Hood of Optuna</h3><p><em>If you are already familiar with Optuna, feel free to move on to the next section.</em></p><p>Optuna finds the best hyperparameter configuration from a number of possible hyperparameters. Under the hood, there are five major components in Optuna:</p><ol><li><a href="https://optuna.readthedocs.io/en/latest/reference/study.html">Study</a></li><li><a href="https://optuna.readthedocs.io/en/latest/reference/storages.html">Storage</a></li><li><a href="https://optuna.readthedocs.io/en/latest/reference/trial.html">Trial</a></li><li><a href="https://optuna.readthedocs.io/en/latest/reference/samplers.html">Sampler (includes a figure describing how these components interact)</a></li><li><a href="https://optuna.readthedocs.io/en/latest/reference/pruners.html">Pruner</a></li></ol><p>A Study object is responsible for finding the set of hyperparameters that achieves the best value of the user-defined objective function. One set of hyperparameters and values of the objective function obtained by this set are monitored by one Trial. Trial reports those values and its ID (Trial.number) to Storage of Study. Sampler is in charge of the sampling processes of hyperparameters. Pruner stops unpromising Trials by comparing its intermediate values with those of previous Trials. Note that Pruner is not always enabled. It works only when you report the intermediate values through Trial.report within your objective function.</p><h3>How Pruning Algorithms Work</h3><p>Before diving into Hyperband, let us go through an example of a basic pruning algorithm to show how it works and the best hyperparameter configuration might be overlooked. Every epoch, we cut off the worst half of the running configurations. Assume there are eight hyperparameter configurations and learning curves of their complete training are as follows. Note that these curves are NOT available before hyperparameter optimization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kOaklHQM3P45dDrK" /></figure><p>First, we run 8 configurations for one epoch to collect the validation accuracy of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*75Of7P1RKpsI_9QT" /></figure><p>Here, the bottom four configurations, i.e., 1, 4, 2, and 3 are stopped. We repeat this procedure until there is only one configuration. So, we run the remaining four configurations for another epoch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xj_irgzGxNAESQcW" /></figure><p>As of epoch 2, 5 and 8 are pruned. The algorithm fails to detect that 8 is the ultimate best configuration at this moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IxzgN6YaIuiFLGO1" /></figure><p>After 3 epochs of training, configuration 7 is better than 6. 7 will be trained fully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HyWN2AKWEReEk_6u" /></figure><p>As you might notice, pruning algorithms might stop the best configuration prematurely, however, there is no way to prevent this as we cannot predict learning curves 100% accurately with any algorithms.</p><h3>Optuna’s Pruning Algorithms So Far</h3><p>Optuna has provided basically two pruning algorithms: median stopping rule [1] and (asynchronous) Successive Halving (SHA) [2][3] named MedianPruner and SuccessiveHalvingPruner, respectively. Median stopping rule “prunes if the trial’s best intermediate result is worse than median of intermediate results of previous trials at the same step” (quote from Optuna documentation). SHA introduces the concept of budget (hereafter, denote it as B) that is equivalent to the computational resources of HPO experiment. The design principle is that allocating more resources, e.g., epochs, to promising trials by reducing the number of trials to half, i.e., stopping unpromising ones. In this situation, the intervals grow exponentially by the user-defined ratio (e.g. 3). However, as its focus is on faster configuration evaluation rather than hyperparameter configuration selection of Bayesian Optimization, Successive Halving has a hyperparameter for itself related to the number of trials to examine (hereafter, denote it as n). This means that SHA has a tradeoff between n and B. When it requires more resources to differentiate better configurations from worse ones, i.e. learning curves can change drastically in their training, it’d be better to set n small to reduce the wrong judgment. Contrary, if learning curves change monotonically, i.e., their order does not change during the training, we have to set n larger to expand the probability of finding better hyperparameters.</p><p>For further details, please refer to the original papers and <a href="https://blog.ml.cmu.edu/2018/12/12/massively-parallel-hyperparameter-optimization/">the post by the authors</a>.</p><h3>What is Hyperband</h3><p>As mentioned briefly, Successive Halving has hyperparameters and they are in the relationship of trade-off. This trade-off, called “n versus B/n” in the Hyperband paper, affects the final result of HPO. Of course, all the trials can be correctly sorted and selected if the final results are available. But, pruning tries to stop unpromising trials as quickly as possible and how learning curves are shaped is totally different. Also, to judge which trial is better than the other with enough confidence, there should be enough gap between the two trials. If there is some prior knowledge about the tendency of learning curves are available a priori, we can choose appropriate n. However, what makes things complex and challenging is that the characteristic of learning curves is up to the task.</p><p>To address this trade-off, Hyperband runs multiple Successive Halving instances with different n values and each instance is responsible for a portion/subset of the trials, called brackets.</p><h3>Implementing Hyperband in Optuna</h3><p>In this section, first I’ll show you the most naive implementation and discuss weak points of it. Then, necessary characteristics of Hyperband implementation, difficulties in realizing those features, and how we resolved them are explained.</p><h3>The Naive Implementation and What it sacrifices</h3><p>The simplest implementation of Hyperband with Optuna is that using multiple Studys as follows.</p><pre>def main():<br>    best_trials = []<br>    for bracket_config in all_bracket_configs:<br>        sampler = ...<br>        pruner = SuccessiveHalvingPruner(**bracket_config)<br>        study = optuna.create_study(sampler=sampler, pruner=pruner)<br>        study.optimize(objective, ...)<br>        best_trials.append(study.best_trial)<br>    best_trial = min(best_trials, key=lambda trial: trial.value)<br>    ...</pre><p>This is solid as it’ll be easier to implement the algorithm described in the paper truly but only if you don’t care how to resume this optimization workflow (optuna.load_study), how to manage storage, and/or how to execute this implementation in a distributed environment correctly. Since distributed execution is one major feature of Optuna, it is not desirable to give up it partially just by adding a new feature however it’s impactful.</p><h3>Challenges to Keep the Current Design and How We Resolved</h3><p>So we decided to implement Hyperband in the same manner as the other pruners. In this way, there were three challenges:</p><ol><li>how to choose a bracket for a new trial</li><li>how to compute budgets of brackets</li><li>how to collect trials of one single bracket in pruning/sampling phases</li></ol><p>In each section, the design decisions we made follow the description of challenges.</p><h4>Challenge 1 &amp; 2: Design of Hyperband</h4><p>By definition, budget is a thing related to time, not the number of trials. So, for each bracket to consume approximately the same budget, it’s necessary to give a reasonable number of trials to brackets. Also, as Optuna allows users to run study.optimize infinitely long and stop by ctrl+c, both n_trials and timeout can be None, leading to null budget information. Thus, we decided to introduce randomness in bracket selection and bracket budget computation algorithms. This is because no algorithm can satisfy all the requirements of Hyperband and the constraints of Optuna. This design choice made the implementation a bit different from the algorithm described in the paper, however, the performance is solid in the benchmark. Also, budget computation is a bit modified but the trends of budget values follow the paper. It’s worth mention that in spite of this naive allocation, it defeats the other pruning algorithms in benchmarks executed with <a href="https://github.com/sile/kurobako">sile/kurobako</a>.</p><h4>Challenge 3: How to Collect Appropriate Trials</h4><p>As to the implementation of trial collection in pruning/sampling, the most arguable thing. Optuna has kept pruning module and sampling module loosely coupled and this has contributed to the modularity of Optuna (This means that Study module is responsible for a bunch of tasks). So, without any modification, brackets and samplers will take into consideration the history of all the trials including ones that are monitored by the other brackets. Therefore, we needed to implement some filtering logic while keeping samplers and pruners loosely-connected as possible. We had two ideas of how to resolve.</p><p>One is adding bracket index to trials.use_attr and setting the list of trials of the same bracket as its attribute for samplers to get access to the list of trials. The required changes can be found in <a href="https://github.com/optuna/optuna/pull/785">optuna/optuna#785</a>. As you can see, the number of changed files is 22. This is not reasonable from the perspective of maintainability. Also, most of the changes are really ad-hoc while they are required only by HyperbandPruner.</p><p>The other is wrap a study object, especially get_trials that filters out trials based on the current trial’s bracket index as done in <a href="https://github.com/optuna/optuna/pull/809">optuna/optuna#809</a>. This can be implemented in a way that we can encapsulate the required ad-hoc changes inside hyperband implementations, i.e. HyperbandPruner class. How? We have implemented a wrapper class of Study whose get_trials method effectively filters out irrelevant trials before returning the list of trials. This design made it simple to make TPESampler compatible with Hyperband. Since TPESampler uses the history of HPO, it has to track which bracket monitors which configurations. This seems to require a bunch of changes, but as you can see in <a href="https://github.com/optuna/optuna/pull/828/files">https://github.com/optuna/optuna/pull/828</a>, the changes are compact.</p><h3>Benchmark Results</h3><p>Takeaway: the current implementation works well and easy to use.</p><p>The task is chosen from <a href="https://arxiv.org/abs/1905.04970">HPOBench</a> [5].</p><p>First of all, to show the benefit of Hyperband, we ran the experiment of TPESampler and different pruners. In the below figure, deep green represents the HyperbandPruner and it achieves the best performance. Intuitively, Hyperband mitigates the burden of finding the best eta value of SuccessiveHalving. Naturally, some Successive Halving instances would beat Hyperband if they use good hyperparameters. Though, it’s not true in this benchmark. We attribute this to the nature of TPESampler: it sometimes gets stuck at saddle points while HyperbandPruner virtually four TPESamplers leading to the avoidance of those local optima. It might be worth mentioning that the task is different from that of the Hyperband paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*PQgHqRp7i77Tkjc_" /></figure><h4>RandomSampler</h4><p>As mentioned beforehand, SuccessiveHalvingPruners with different eta, a parameter that affects n, values show different characteristics. More specifically, the case of eta=0 is terrible while the others show achieve better and similar scores. This is “n versus B/n tradeoff.” Also, you can see that Hyperband is not the best but it looks competitive considering that we don’t need to run different Successive Halving experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*m8K0lvjop29uT1RA" /></figure><h3>Conclusion</h3><p>In this post, I briefed Optuna and how I implemented Hyperband. The current implementation works really well including that sometimes well configured Successive Halving is better, however, it’s experimental and there’s room to improve how to select a bracket for a Trial and how to compute budgets for SuccessiveHalvingPruners run by HyperbandPruner. Optuna team, really welcome any comments, feedback, and thoughts! Feel free to comment, join Gitter, and enjoy Optuna!</p><h3>Cited Works</h3><p>[1] Google Vizier: A Service for Black-Box Optimization, <a href="https://research.google.com/pubs/archive/46180.pdf">https://research.google.com/pubs/archive/46180.pdf</a></p><p>[2] <a href="https://arxiv.org/abs/1502.07943">[1502.07943] Non-stochastic Best Arm Identification and Hyperparameter Optimization</a></p><p>[3] <a href="https://arxiv.org/abs/1810.05934">[1810.05934] Massively Parallel Hyperparameter Tuning</a></p><p>[4] <a href="http://jmlr.org/papers/volume18/16-558/16-558.pdf">Hyperband: A Novel Bandit-Based Approach to Hyperparameter Optimization</a></p><p>[5] <a href="https://arxiv.org/abs/1905.04970">[1905.04970] Tabular Benchmarks for Joint Architecture and Hyperparameter Optimization</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93b0cae1a137" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optuna/optuna-supports-hyperband-93b0cae1a137">How We Implement Hyperband in Optuna</a> was originally published in <a href="https://medium.com/optuna">Optuna</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get Better fastai Tabular Model with Optuna]]></title>
            <link>https://medium.com/@crcrpar/optuna-fastai-tabular-model-001-55777031e288?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/55777031e288</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[optuna]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[hyperparameter-tuning]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Fri, 01 Nov 2019 03:01:01 GMT</pubDate>
            <atom:updated>2020-01-23T06:04:32.370Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*VsTibeR2MCbtEN2IKtrMkw.png" /></figure><p><em>Note: this post uses </em><em>fastai v1.0.58 (PyTorch v1.3.0)and </em><em>optuna v0.17.1.</em></p><h3>Introduction</h3><p>Optuna is a hyperparameter optimization framework applicable to machine learning frameworks and black-box optimization solvers. We can use Optuna with ease in our code by defining an objective function to be optimized. See examples <a href="https://github.com/pfnet/optuna/tree/v0.17.1/examples">in the repository</a>.</p><p><a href="https://docs.fast.ai">fastai</a> library makes it easier to try deep learning and provides a bunch of latest techniques (best practices) that enable us to obtain competitive models. <a href="https://docs.fast.ai/train.html#lr_find">learn.lr_find</a> for optimal learning rates, learn.fit_one_cycle for <a href="https://www.fast.ai/2018/07/02/adam-weight-decay/">superconvergence</a>, and <a href="https://docs.fast.ai/callbacks.mixup.html#MixUpCallback">MixUpCallback</a> Callback for the de facto data augmentation. Also, it supports features for data validation (<a href="https://docs.fast.ai/tutorial.data.html">Look at data | fastai</a>) and investigation of trained computer vision models (<a href="https://docs.fast.ai/vision.interpret.html">Computer Vision Interpret [fastai]</a>).</p><p>FastAI has three applications, <strong>vision</strong>, <strong>text</strong>, and <strong>tabular</strong>. Fastai focuses on fine-tuning in vision &amp; text as there are a ton of neural network models trained on massive datasets, e.g., ImageNet for vision models and texts collected from the web for language models. Those models are said to have a common sense (I mean they have enough basic knowledge so that they can quickly adapt to new tasks). However, as to the last application, <strong>tabular</strong>, there are no appropriate datasets for pretraining because it seems almost impossible to define what is a general feature of tabular tasks. If you look for a tabular dataset in Kaggle, there are a bunch of competitions, for example, <a href="https://www.kaggle.com/c/instacart-market-basket-analysis">Instacart</a>, <a href="https://www.kaggle.com/c/rossmann-store-sales#">Rossman</a>, and <a href="https://www.kaggle.com/c/titanic">titanic</a>.</p><h3>Optimize TabularModel for Rossman data</h3><p>So, I’ll try to get a better TabularModel trained on Rossman dataset than that obtained in fastai’s lecture by letting Optuna find the optimal number of layers and units of each layer, and dropout ratio.</p><p>The task is <a href="https://www.kaggle.com/c/rossmann-store-sales#">https://www.kaggle.com/c/rossmann-store-sales#</a>. In this competition, it’s expected to create a model that predicts future store sales of the coming six weeks. As you can see in the <a href="https://www.kaggle.com/c/rossmann-store-sales/data">Data fields</a>, there are both categorical and numerical features. In TabularModel, numerical features are handled as one vector, and each categorical feature is embedded into a vector. This technique is called <a href="https://arxiv.org/abs/1604.06737">Entity Embedding</a>. Intuitively, Entity Embedding enables models to learn some useful relationships between instances of categorical features from training dataset. So, TabularModel has some embedding layers and groups of linear (a.k.a. dense), batchnorm, and dropout. The activation function is ReLU.</p><p>For those interested in the details of data processing, please see <a href="https://course.fast.ai/videos/?lesson=4">the lesson video</a>. Here, I just use <a href="https://github.com/fastai/course-v3/blob/master/nbs/dl1/rossman_data_clean.ipynb">the preprocessing Jupyter notebook</a> to get the same data used in the lecture.</p><p>In the original notebook, a model is defined as below.</p><pre>learn = tabular_learner(data, layers=[1000,500], ps=[0.001,0.01], emb_drop=0.04, <br>                        y_range=y_range, metrics=exp_rmspe)</pre><p>This means that the model has two hidden layers and each layer applies dropout with the ratio of 0.001 and 0.01. Also, it uses dropout with the ratio 0.04 to the concatenated vector of embeddings of categorical features. See <a href="https://docs.fast.ai/tabular.learner.html#tabular_learner">the docs</a> for the details. Therefore, I’ll try optuna to find better hyperparameters of</p><ul><li>the number of layers</li><li>the number of units each layer has</li><li>the dropout ratio of each layer</li><li>the dropout ratio of a concatenated vector</li></ul><p><strong>Define fastai TabularModel with Optuna</strong></p><p>To use optuna in your training scripts, the only thing to do is defining an objective function which takes optuna.trial.Trial as its input and returns the value to optimize, for instance, accuracy/loss on validation dataset as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9261118f09010fd85d05eceb955e9e63/href">https://medium.com/media/9261118f09010fd85d05eceb955e9e63/href</a></iframe><p>As a reference, in the original notebook, fit_one_cycle was used three times, and each fitting ran for five epochs. All exp_rmspescores on validation were <strong>0.105433</strong>,<strong> 0.116344</strong>, and <strong>0.126323</strong>. By optuna optimization with 100 trials, I got <strong>0.102660</strong>. The details are below.</p><pre>Best trial:<br>  Value:  0.10201516002416611<br>  Params:<br>    n_layers: 3<br>    n_units_layer_0: 800<br>    dropout_p_layer_0: 0.1<br>    n_units_layer_1: 900<br>    dropout_p_layer_1: 0.2<br>    emb_drop: 0.1</pre><h3>Faster Optimization with Pruning</h3><p>While I did get a better model, Optuna ran all the trials (100 trials). Approximately, I ran `100 trials x 5 epochs/trial = 500 epochs`. However, all the trials do not use reasonable hyperparameters due to the randomness of each hyperparameter’s sampling.</p><p>So, intuitively, we can do early stopping to some trials with bad hyperparameters to reduce the total time. This early stopping in hyperparameter optimization is <strong>Pruning </strong>and Optuna supports some strategies for pruning like <a href="https://arxiv.org/abs/1502.07943">Successive Halving</a> and callbacks for popular machine learning frameworks such as Keras, MXNet, Chainer, and PyTorch Lightning. See <a href="https://optuna.readthedocs.io/en/latest/reference/integration.html">the documentation</a> for the list.</p><p><strong>Implement </strong><strong>FastAIPruningCallback(TrackerCallback)</strong></p><p>In fastai, training and validation loops are abstracted inlearn.fit or learn.fit_one_cycle. Pruning is a variant of EarlyStopping, and the only difference is that pruning is done by optuna.trial.Trial, not Learner. So I implemented the callback as in <a href="https://github.com/pfnet/optuna/pull/585/files">this PR for Optuna</a> and a simpler implementation is below.</p><pre>class FastAIPruningCallback(TrackerCallback):<br>    def __init__(self, learn, trial, monitor):<br>        # type: (Learner, optuna.trial.Trial, str) -&gt; None<br><br>        super(FastAIPruningCallback, self).__init__(learn, monitor)<br><br>        self.trial = trial<br><br>    def on_epoch_end(self, epoch, **kwargs):<br>        # type: (int, Any) -&gt; None<br><br>        value = self.get_monitor_value()<br>        if value is None:<br>            return<br><br>        self.trial.report(value, step=epoch)<br>        if self.trial.should_prune():<br>            message = &#39;Trial was pruned at epoch {}.&#39;.format(epoch)<br>            raise optuna.structs.TrialPruned(message)</pre><p>By incorporating pruning, the final result might be less competitive than that of a study without pruning because it is almost impossible to predict learning curves precisely. However, the time of optimization should be reduced a lot. And the result is as follows:</p><pre>Study statistics:<br>  Number of finished trials:  100<br>  Number of pruned trials:  63<br>  Number of complete trials:  37<br>Best trial:<br>  Value:  0.10323499143123627<br>  Params:<br>    n_layers: 3<br>    n_units_layer_0: 900<br>    dropout_p_layer_0: 0.1<br>    n_units_layer_1: 1100<br>    dropout_p_layer_1: 0.15000000000000002<br>    emb_drop: 0.05</pre><p>The summary of this post is the below table. Trainings are done with GTX 1080Ti.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0dee3da91e36411ceea7f953347b4464/href">https://medium.com/media/0dee3da91e36411ceea7f953347b4464/href</a></iframe><p>Also, as the table shows, the total time needed by Optuna is reduced from852to 555 minutes, about 35% reduction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*JVqbgnb2SN4tHJIkgCJzCw.png" /><figcaption>How Pruning Effects Study Time</figcaption></figure><p>The script used in this blog post is <a href="https://github.com/crcrpar/fastai-optuna-rossman">https://github.com/crcrpar/fastai-optuna-rossman</a>.</p><p>fin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55777031e288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift for TensorFlow meetup in Tokyo]]></title>
            <link>https://medium.com/@crcrpar/swift-for-tensorflow-meetup-in-tokyo-66a27904d9d1?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/66a27904d9d1</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-for-tensorflow]]></category>
            <category><![CDATA[mlir]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[compilers]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Fri, 12 Jul 2019 06:15:21 GMT</pubDate>
            <atom:updated>2019-07-12T12:42:26.718Z</atom:updated>
            <content:encoded><![CDATA[<p>On 2019/07/10, I attended <a href="https://connpass.com/event/138112/">Swift for TensorFlow meetup #1</a>.</p><p>First, I want to say thank you to date-san for kick-off, some members from mercari for offering awesome event space and food&amp;snacks, Eugene for solid tutorials with Colab, omochi-san for the great general introduction to neural network and frameworks for it in Japanese, and of course, all the attendees with curiosity.</p><p>I expected the skills of attendees would be either iOS or Machine Learning. However, some experts of compilers took part and asked high-level questions. I have never imagined that situation, though, interactions of iOS, ML, and compiler engineers was so exciting.</p><p>The first speaker was omochi-san, an iOS developer and an expert of Swift compiler. He briefed major components of Deep Learning from differentiation to define-by-run &amp; define-and-run. After this review, he explained why Swift for TensorFlow is promising and what he expects S4TF to be, for instance, S4TF to be the killer app for Swift to be general purpose language from the perspective of the pie of usage.</p><p>The second and main speaker was Eugene Burmako working for S4TF team. Thanks to the omochi-san’s excellent introduction talk, Eugene seemed to skip some slides and directly dive into Jupyter notebook examples on Colab.<br>S4TF has many cool features, but, for me, the best cool things are that its compiler can differentiate our custom functions if they are mathematically differentiable and its compiler extracts Tensor operations and gives them to TensorFlow runtime (called <strong>G</strong>raph <strong>P</strong>rogram <strong>E</strong>xtraction but deprecated now). Additionally, the compiler tells us why the function is not differentiable with rich messages.</p><p>In the last, while I’m not familiar with TensorFlow, S4TF, and compilers, I talked about MLIR — a new intermediate representation which helps to unify complicated TensorFlow compiler ecosystem and at the same time, it can improve current Clang compilation flow. Because studying new things always gives me a new perspective on what I am familiar with or accustomed to, and I believed it would be a great opportunity to get feedback with some expertise that sometimes is difficult to obtain by self-taught.</p><p>The preparation process was so naive &amp; straightforward. First googled “MLIR” and found videos in 2019 LLVM European Developers Meeting where some developers working for MLIR did a general introduction to MLIR and tutorials about how to create a toy language with MLIR. I will explain why MLIR is needed what MLIR supports; however, I recommend that you watch the conference talk and tutorial :)</p><p>Today, TensorFlow supports some frameworks optimized for inference: TensorFlow Serving, TensorFlow Lite including NN API, TensorRT, nGraph, Core ML. Also, TensorFlow enhances its performance of models by supporting XLA, which is good at optimizing computational graph (aka dataflow graph) by, for instance fusing operations using knowledge about them. Therefore, there are various kinds of computational graph representations that TF needs to support or target: TF Graph, XLA HLO, TF Lite, Tensor RT, nGraph, and Core ML. What makes things worse, those representations are similar but different. Also, since machine learning techniques are evolved day by day, there will be more and more operations to support as their API.</p><p>In MLIR type system, Scalar type including <a href="https://en.wikipedia.org/wiki/Bfloat16_floating-point_format">bfloat16 </a>used in TPU, Vector type, and Tensor type which allows dynamic shape multi-dimensional arrays. Also, MLIR Operations support declarative operation definition, which eases the work to implement tons of ML operations in C++. There’s no fixed list of operations, and it’s totally extensible. One cool thing of MLIR is that its operations can take/return multiple arguments/values. Also, they can be configured using attributes. This attribute should be important for epsilon value of BatchNorm, strides &amp; paddings of Convolution. Furthermore, operations can have more than one region.</p><p>This rich &amp; flexible spec of MLIR will ease the cumbersome work to translate an operation of framework A to corresponding operations of framework B by defining dialects using MLIR. In MLIR Dialects, we need to define their original types, pass managers, and so on.</p><p>So far, we’ve seen that MLIR leaves dialects to keep structures and supports declarative operation definitions using dialects. But how about translating an operation of one framework to another? To access this, MLIR provides M-to-N pattern.</p><p>Finally, MLIR can improve Clang compilation flow by enabling us to implement C/C++ specific higher level IR (= CIL) as SIL in Swift. Also, we can make OpenMP as its dialect. By this, it will be more accessible to optimized C/C++ (with OpenMP) code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66a27904d9d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lessons from fastai Machine Learning]]></title>
            <link>https://medium.com/@crcrpar/lessons-from-fastai-machine-learning-355d4a8c75b4?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/355d4a8c75b4</guid>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[random-forest]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 06:43:45 GMT</pubDate>
            <atom:updated>2019-02-03T06:43:45.841Z</atom:updated>
            <content:encoded><![CDATA[<p>I watched all the lessons after a long time from [this post](<a href="https://medium.com/@crcrpar/what-i-learned-from-fast-ai-ml-till-5-510040c6d91f">https://medium.com/@crcrpar/what-i-learned-from-fast-ai-ml-till-5-510040c6d91f</a>). However, the last couple of lessons had some contents like Kaggle Rossman competition that were done in Deep Learning course. So, I did not take notes so much.</p><p><strong>The most impressive contents</strong> are<br>* Implement Random Forest from scratch using numpy and optionally Cython. Here, I think we can use <a href="https://cupy.chainer.org/">CuPy: A NumPy-compatible matrix library accelerated by CUDA</a>.<br>* Random Forest interpretation: feature importance, partial dependence, tree interpreter type 2 (explain one prediction), and extrapolation.<br>As to interpretation, I think <a href="https://twitter.com/christophmolnar">Christoph Molnar</a>’s “<a href="https://christophm.github.io/interpretable-ml-book/">Interpretable Machine Learning</a>” is must-read because the book covers conventional machine learning and methods explaining neural networks’ predictions.</p><p>But, because I’ve been busy so I copy&amp;paste my log here. I might elaborate on this post afterward.<br>Also, the last couple of lessons did some contents done in fast.ai Deep Learning course.</p><h3>What Impressed Me Most</h3><p>One lesson from the last half is what really matters is feature importance, not AUC score nor accuracy. And another lesson is Random Forest returns the average of neighbor points in the tree space. So, if the inputs are distant from the space, predictions should be the average of whole training dataset samples.</p><p>Hereafter, I just copy my notes. So feel free to stop reading :)<br>I’ve been busy so I copy&amp;paste my log here. I might elaborate on this post afterward.<br>Also, the last couple of lessons did some contents done in fast.ai Deep Learning course.</p><p><strong>Lesson 6</strong></p><p>Why do I need machine learning?<br>the drivetrain method<br>Examples of how ppl use machine learning in business (in slide).<br>Horizontal applications.</p><p>Churn: to predict who is going to leave. <br>jeremy howard data products book would be interesting.<br>defined objective, levers, data, models.<br>levers = what inputs can we control<br>data = what data we can collect<br>models = how the levers influence the objective<br>levers for churn prediction is…<br> motivate users not to leave the service?<br> change the prices?<br>clarify what we can actually do!<br>after this, clarify what data is available or necessary.<br>In practice, care more about simulation.<br> build a simulation model;<br> predict what happens by what the model predicts.<br>~~optimization model basically ~~<br>predictive model goes into simulation model giving the predictions.<br>simulation model predicts the probability the target changes his/her behavior by the action we made.</p><p>about interpretation more of prediction.<br>Use feature importance to decide the next action!</p><p>In business, what really matters is feature importance, i.e., understanding not AUC score.</p><p>— -</p><p>vertical applications<br>readmission risk<br>a predictive model is helpful of course but feature importance would play a role.<br>you can build a chart w/o machine learning, but if with machine learning and its feature importance, the chart will be much improved and help decision making.</p><p>there is still skepticism from unfamiliarity with the approach to data.</p><p>— — break — -<br>random forest interpretation.<br>confidence based on tree variance.</p><p>how to calculate feature importance for a certain feature. type 1<br>how to calculate from a trained random forest?<br>- shuffle randomly the column and calculate the score and the gain.<br>jeremy looks at the relative difference.<br>The scalars themselves are not important to him?<br>also plots of gain is helpful. plateau of low values features would be not helpful.</p><p>Partial Dependence.<br>there always be a bunch of interactions of different features.<br>So 2D plot cannot describe this and would be a big problem.<br>How to calculate?<br>by leaving every other features as is and replacing the values with a single value, and the calculate the prediction. Repeat this!<br>partial dependence plot tells the underlying truth.</p><p>Tree Interpreter type 2<br>feature interpretation for a specific observation<br>like a waterfall</p><p>Extrapolation<br>(live coding)<br>gain from multiple enclosures is the interaction of them.<br>RF just returns the average of neighbor points in the tree space.<br>If the inputs are really far from the samples in training dataset,<br>it just returns the average of the whole training dataset.<br>ATM, no way to handle this, but there are time series analysis and neural net.</p><p><strong>Lesson 7</strong></p><p>random forest and neural nets are 2 keys.<br>a lot of progress has been made in decision tree based methods like random forest and GBM.<br>RF is harder to screw up than GBM.</p><p>22 observations. t-distribution turns to normal distribution.<br>validation.<br>standard error = std / sqrt(n)</p><p>oversampling till the number of instances in each class is the equal to the most common class is the right thing to o.<br>Or, stratified sampling to create mini batches.</p><p>— -</p><p>bulldozer kaggle competition.<br>sample rows w/ replacement</p><p>Decision Tree doesn’t have randomness.<br>Randomness happens in creating a bunch of decision trees in Random Forest, i.e., choosing indexes.</p><p>how to find variables to split in decision tree?<br>lhs.std() * lhs.score + rhs.std() * rhs.score()<br>O(N) implementation using sqrt( x**2 — mean(x) ** 2 / N)</p><p>class A<br> def foo(self, …)<br>def foo(self, …)<br>A.foo = foo</p><p>Start from assumption and assuming I’m wrong in coding.<br>ternary operator is helpful.</p><p>sklearn’s Random Forest is written in Cython.<br>First time, it shoulld be slower.</p><p>Working with NumPy (Cython docs)<br><a href="https://cython.readthedocs.io/en/latest/src/tutorial/numpy.html">https://cython.readthedocs.io/en/latest/src/tutorial/numpy.html</a></p><p>RF is a nearest neighbor methods.</p><p><strong>Lesson 8</strong></p><p>pickle works for nearly every python object but not optimally.<br>pickle files are only for Python.</p><p>In random forest, normalization to independent variables doesn’t matter.<br>The order does matter. Random Forest ignores the scale or statistical distribution problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=355d4a8c75b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I Learned from fast.ai ML till 5]]></title>
            <link>https://medium.com/@crcrpar/what-i-learned-from-fast-ai-ml-till-5-510040c6d91f?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/510040c6d91f</guid>
            <category><![CDATA[random-forest]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[practical-technique]]></category>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Sun, 21 Oct 2018 03:09:20 GMT</pubDate>
            <atom:updated>2018-10-21T03:09:20.086Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is about what I learned from fastai Machine Learning course published this September.<br><strong><em>Edit</em></strong> (2018/10/20): Since fastai course 1 V3 starts in a few days. I stopped watching 6~12 lectures.<br><strong><em>Note</em></strong>: In this post, I use fastai v0.7, not v1.0.</p><h3>What is Random Forest?</h3><p>Random Forest is one of the most famous machine learning algorithms because it is easy to use and applicable to both classification and regression problems even if each data sample is composed of both categorical (e.g. ZIP code) and continuous (e.g. price) variables. Also, random forest avoids BAD overfittings and it can achieve fairly good results with a few pieces of feature engineering. Further, data samples do not need to be i.i.d. samples while most linear machine learning algorithms require this property. So, it is a good point to start any projects related to machine learning.</p><h3>Use Random Forest To Understand Data More!</h3><p>Random Forest consists of a bunch of trees. In scikit-learn, we can choose the number of trees by passing 1 ton_estimators argument. In this case, the trained model is <em>decision tree. </em>So, the visualization of your model tells you which features are more important/effective than the others.</p><p>Let me show you an example from <a href="https://github.com/fastai/fastai/blob/master/courses/ml1/lesson1-rf.ipynb">Lesson 1 notebook</a>. Where the goal is to predict the sale price (= regression) of bulldozers. Details are <a href="https://www.kaggle.com/c/bluebook-for-bulldozers/">Kaggle bulldozers competition</a>. This dataset has both categorical and continuous variables and each data sample has a timestamp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2UxdetuSKGz3XlC7oX71Ow.png" /><figcaption>Visualization of the decision tree from lecture notebook.</figcaption></figure><p>In the above figure, every single node has 4 lines: 1) feature (column) name ≤ criterion, 2) Mean Squared Error = loss value, 3) # of samples included, 4) average of predicted sale prices. As you can see, more left features are more important/effective than others. In this figure, some features are categorical though, their criteria are float numbers. Why? Because categorical variables are translated into integers. Of course, sometimes categorical variables have an order, but usually, reflecting the order to the translation doesn’t improve scores. Another thing I want to mention is fastai provides really useful draw_tree function as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*eMKcYGsLE3vv7l5RFybo7A.png" /><figcaption>draw_tree function</figcaption></figure><h3>Random Forest in Supervised Learning</h3><p>In the above paragraph, I show that machine learning sometimes helps us know more about datasets. Though, our original goal is to get super cool models which can predict values/labels of unknown data samples. Also, literally, a random forest is composed of a bunch of decision trees. Every single tree is like a tree used in the previous section. In other words, averaging predictions to make outputs more accurate with less variance. This averaging method is usually called <em>bagging. </em>As a side note, we can use bagging when there are different models like a pair of SVM and Random Forest. In scikit-learn’s random forest, n_estimators defines how many trees are used to build a random forest. So, larger n_estimators means less variance and higher accuracy. You can check this effect by changing n_estimators argument of Random Forest. But note that there is a limit where you cannot improve any more. When you use Random Forest and your model has a serious gap between a training set and corresponding validation/development set, it is a good choice to set oob_score true. <strong>OOB </strong>stands for “Out-of-bag”. What is out-of-bag score? Out of bag score is calculated by using samples not used in each tree building. So it is like quasi-validation score intuitively. However, this score is usually worse than the validation score.</p><h4>Frequently Tuned Hyper Parameters</h4><p>Of course, there are some parameters frequently tuned. I experimented these parameters’ effects in <a href="https://gist.github.com/crcrpar/6cc6b852540e932ec8f94f0b668c5027">this notebook</a>.</p><ol><li>n_estimators : Number of trees composing one forest.</li><li>max_depth : Maximum depth (= height) of each tree. If not specified, the depth is up to min_samples_leaf.</li><li>min_samples_leaf : Number of samples whom each leaf node has. In other words, the minimum number of samples to expand nodes / deepen trees.</li><li>max_features: Number of features (columns) to obtain the best split. If this is not specified, in each step, the algorithm looks for all the remaining columns. By using this argument, every single tree is going to be less accurate but have different properties. This leads to better models.</li></ol><h4>Technique for Categorical Variables</h4><p>Random Forest doesn’t know the order of categorical variables until we tell. For example, if one category is about the size of a product: large, middle, small, then we assume labels to be 2, 1, and 0 or 1, 0, and -1, respectively. However, if labels are messed up like high-&gt;1, middle-&gt;2, and small-&gt;0, a model doesn’t know anything at all. This situation goes worse when the number of classes in a category is large. One way to attack this is one-hot encoding. It is easy to implement that add #classes columns and each column represents whether the sample has the attribute represented by the column. So, if you apply one-hot encoding to high, middle, and small, then adding high column, middle column and small column to the tabular dataset and every single row sets 1 in one of 3 columns. This technique might be ineffective, but usually changes the order of feature importance. So there will be a new understanding of your datasets.1</p><h3>Feature Importance</h3><p>One easy way to tell the importance is calculating the difference between scores on the dataset where one column is randomly shuffled and the original validation dataset. After applying this method to all the columns one by one, you will get the list of gaps. Intuitively, if the gap is small, the shuffled column (feature) is not important.</p><p>Another way is <em>partial dependence</em>. This is obtained by replacing one column with one constant value. By plotting this, we can know whether something extraordinary happens or not.</p><h3>When you use temporal datasets…</h3><p>Datasets containing timestamps is more difficult than other datasets to split them into training, validation, and test. Because if a validation and/or test dataset includes older samples than ones of training, your model predicts using strong prior knowledge about validation and/or test. So if your dataset is related time, splitting is done according to chronological order. Hence prediction on test dataset is executed after finding good hyperparameters and retrain a model using them on training + validation dataset.<br>Also, it is worth trying to remove implicitly time-related variables from model inputs. To detect whether a variable is time-related or not, train a model to predict each sample is from training or validation dataset. Easy to predict variables should be removed and it will improve your models.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=510040c6d91f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[some deep learning algorithm related to fashion]]></title>
            <link>https://medium.com/@crcrpar/some-deep-learning-algorithm-related-to-fashion-b55e471fe6aa?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/b55e471fe6aa</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Sat, 10 Feb 2018 02:36:11 GMT</pubDate>
            <atom:updated>2018-02-10T02:36:11.184Z</atom:updated>
            <content:encoded><![CDATA[<p>In this January, I have worked on survey on virtual try-on and new pose image synthesis methods, using deep learning, mainly GANs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fspeakerdeck.com%2Fplayer%2F783a7e50be2f4022b9ca580e748c40a2&amp;url=https%3A%2F%2Fspeakerdeck.com%2Fcrcrpar%2Fdeep-learning-for-clothes-and-changing-pose&amp;image=https%3A%2F%2Fspeakerd.s3.amazonaws.com%2Fpresentations%2F783a7e50be2f4022b9ca580e748c40a2%2Fslide_0.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=speakerdeck" width="710" height="463" frameborder="0" scrolling="no"><a href="https://medium.com/media/37d00afb9d12372283793a45a380c62a/href">https://medium.com/media/37d00afb9d12372283793a45a380c62a/href</a></iframe><p>Algorithms mentioned in the above slide are beneficial, however, most of them utilize other pre-trained models like open pose which is not free for commercial use. In addition to this, some use pre-trained semantic segmentation models tuned for ATR Human Parsing dataset. The reason they use another model is for main image-generating model to clarify the areas of faces and clothes in order to generate more vivid and sharp images.</p><p>Around these methods, there is one critical problem: no clear criterion to evaluate models’ outputs. There is only one, qualitative evaluation. We need to devise one. Another problem is that most of them apply only to tops and they are vulnerable human parts such as front arms and hair.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b55e471fe6aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[note on Style Transfer methods]]></title>
            <link>https://medium.com/@crcrpar/note-on-style-transfer-methods-4946594294cb?source=rss-c693456dd6af------2</link>
            <guid isPermaLink="false">https://medium.com/p/4946594294cb</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Masaki Kozuki]]></dc:creator>
            <pubDate>Wed, 22 Nov 2017 14:41:22 GMT</pubDate>
            <atom:updated>2017-11-22T14:41:22.224Z</atom:updated>
            <content:encoded><![CDATA[<p>Style Transfer is one of the most famous deep learning applications. You know one photo obtain the taste of another photo or famous painting to itself, other than a horse is changed to a zebra (called CycleGAN). Style Transfers are different than normal deep learning methods in that using pre-trained convolutional neural networks e.g., VGG16 as one component of the loss function.</p><p>The first algorithm did not generate style applied images by a neural network, generate ones by optimization(LBFGS).<br>So, it didn’t require learning which takes a lot of time but requires a lot of time to “infer” compared to NN based style transfer methods. OTH, NN based style transfer methods require learning time in exchange for fast image generation. Naive NN based style transfer is limited that one trained model can handle one style.</p><p>So what should be solved is how to handle multiple style images in one NN, or generator. As new style transfer methods are invented and/or improved, a new normalizing method Instance Normalization is formulated and used in CycleGAN.<br>Recent advances in NN based style transfer are:</p><ol><li>iterative generation</li><li>newly designed layer which contains multiple style features</li><li>autoencoder based</li></ol><p>Iterative generation is written in “Universal Style Transfer via Feature Transforms” which is to be appeared in NIPS2017. There, Instance Normalization is not used and images are generated in 5 steps, “5” corresponds to the number of blocks in VGG16/19.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4946594294cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>