The post Super-Resolution with Deep Learning for Image Enhancement appeared first on Affine.
]]>Image Super Resolution can be defined as increasing the size of small images while keeping the drop-in quality to a minimum or restoring High Resolution (HR) images from rich details obtained from Low Resolution (LR) images.
The process of enhancing an image is quite complicated due to the multiple issues within a given low-resolution image. An image may have a “lower resolution” as it is smaller in size or as a result of degradation. Super Resolution has numerous applications like:
We can relate the HR and LR images through the following equation:
LR = degradation(HR)
The goal of super resolution is to recover a high-resolution image from a low-resolution input.
Deep learning can estimate the High Resolution of an image given a Low Resolution copy. Using the HR image as a target (or ground-truth) and the LR image as an input, we can treat this like a supervised learning problem.
One of the most used techniques for upscaling an image is interpolation. Although simple to implement, this method faces several issues in terms of visual quality, as the details (e.g., sharp edges) are often not preserved.
Most common interpolation methods produce blurry images. Several types of Interpolation techniques used are :
Image processing for resampling often uses Bicubic Interpolation over Bilinear or Nearest Neighbor Interpolation when speed is not an issue. In contrast to Bilinear Interpolation, which only takes 4 pixels (2×2) into account, bicubic interpolation considers 16 pixels (4×4).
SRCNN was the first Deep Learning method to outperform traditional ones. It is a convolutional neural network consisting of only three convolutional layers:
Before being fed into the network, an image needs up-sampling via Bicubic Interpolation. It is then converted to YCbCr (Y Component and Blue-difference to Red-difference Chroma Component) color space, while the network uses only the luminance channel (Y). The network’s output is then merged with interpolated CbCr channels to produce a final color image. This procedure intends is to change the brightness (the Y channel) of the image while there is no change in the color (CbCr channels) of the image.
The SRCNN consists of the following operations:
LR images are preserved in SR image to contain most of the information as a super-resolution requirement. Super-resolution models, therefore, mainly learn the residuals between LR and HR images. Residual network designs are, therefore, essential.
Up-Sampling Layer¶
The up-sampling layer used is a sub-pixel convolution layer. Given an input of size H×W×CH×W×C and an up-sampling factor ss, the sub-pixel convolution layer first creates a representation of size H×W×s2CH×W×s2C via a convolution operation and then reshapes it to sH×sW×CsH×sW×C, completing the up-sampling operation. The result is an output spatially scaled by factor ss
Enhanced Deep Residual Networks (EDSR)
Furthermore, when super resolution techniques started gaining momentum, EDSR was developed which is an enhancement over the shortcomings of SRCNN and produces much more refined results.
EDSR network consists of :
On comparing several techniques, we can clearly see a trade-off between performance and speed. ESPCN looks the most efficient while EDSR is the most accurate and expensive. You may choose the most suitable method depending on the application.
Further, I have implemented Super Resolution using EDSR on few images as shown below:
This block of code imports all the necessary modules needed for training. DIV2K is the dataset that consists of Diverse 2K resolution-high-quality-images used in various image processing codes. EDSR algorithm is also imported here for further training.
This block of code assigns the number of residual blocks as 16. Furthermore, the super resolution factor and the downgrade operator is defined. Higher the number of residual blocks, better the model will be in capturing minute features, even though its more complicated to train the same. And hence, we stick with residual blocks as 16.
A directory is created where the model weights will be stored while training
Images are downloaded from DIV2K with two folders of train and a valid consisting of both low and high resolution.
Once, the dataset has been loaded, both the train and valid images need to be converted into TensorFlow dataset objects.
Now the model is trained with the number of steps as 30k. The image is evaluated using the generator every 1000th step. The training takes around 12 hours in Google Colab GPU.
Furthermore, the models are saved and can be used in the future for further modifications.
For output, the model is loaded using weight files and further both the images of low resolution and high resolution are plotted simultaneously for comparison.
High-Resolution Images showcased on the right are obtained by applying the Super-Resolution algorithm on the Low-Resolution Images showcased on the left.
Conclusion
You can clearly observe a significant improvement in the resolution of images post-application of the Super-Resolution algorithm, making it exceptionally useful for Spacecraft Images, Aerial Images, and Medical Procedures that require highly accurate results.
References
The post Super-Resolution with Deep Learning for Image Enhancement appeared first on Affine.
]]>The post Affine becomes a new Fellow at the “Fisher Center For Business Analytics at Berkeley Haas” appeared first on Affine.
]]>Affine Inc. announced that it has become a fellow with the “Fisher Center for Business Analytics” (FCBA) at the Berkeley Haas School of Business, University of California. The fellowship envisages research and wide-ranging dialogue with corporate participants and practitioners in areas related to enterprise strategies for Applied Artificial Intelligence and Data Science.
Affine and FCBA will collaborate along multiple dimensions, from applications to methodologies, from governance frameworks to enterprise strategies – all with the objective of further defining the role of data sciences and allied technology in future-ready enterprises.
The flagship event of the program will be an annual summit, discussing one or more key topics of industry interest in analytics,” said Manas Agrawal, CEO at Affine. “The potential theme for the summit could be along industry focus (Gaming, CPG, Logistics) or functional focus (Marketing in the digital economy) or technology focus (AI/ML at scale on cloud). We look forward to developing this into an ongoing knowledge event in the Affine-Academia collaboration.
The Fellowship aims to bring together the research power of FCBA and the industry experience of Affine to create new knowledge in different areas of advancements in analytics. The breakneck pace of innovation in analytics led by AI and cloud computing is also creating a large gap in the frameworks needed to harness this power at Enterprise Scale. The Affine-FCBA Fellowship will work towards generating this knowledge.
Apart from working on joint projects in the most advanced areas of decision sciences and engineering (AI and Cloud), the collaboration will also explore new theories in areas like ownership of analytics in enterprise, right data, engineering strategy,, and the right partnership ecosystem for enterprises.
Mr. Vasseur, executive director at FCBA added – “Connecting research, faculty, and students with enterprise business cases is the best way to transform world-class teaching experience and research into critical analytics skills. .”
The convergence of researchers, practitioners, students, and consumers of this fascinating faculty of data sciences and engineering will break new ground
Affine and FCBA believe in the enormous value that industry-academia collaboration can create in the areas of AI/ML&DS, given the absence of legacy baggage, huge surge in enterprise demand, and prominent computational advances such as HPI, Cloud, Open Source, etc. The fellowship shall strive to contribute lasting knowledge to the ecosystem of practitioners and consumers alike.
Affine is a leading Enterprise Analytics Consulting Firm, working with more than 25 Fortune-500 global enterprises across USA, UK, Europe and the Asia Pacific region, offering capabilities across the continuum of analytical value chain – from Data Modernization to Insights Creation (AI/ML/DS/BI) and Transformation (deployment at scale). The 500 strong practitioners team collaborates with Academia, Enterprises and other technology providers to bring cutting edge solutions to industries like CPG, Gaming, Hi-Tech and Manufacturing.
For More on Affine - www.affineanalytics.com
As the second-oldest business school in the United States, the Haas School of Business at the University of California, Berkeley has been a fountainhead of knowledge creation and dissemination across multiple faculties, from strategy to marketing and finance, including the new paradigm of decision making – AI/ML/DS.
For More on Haas – https://haas.berkeley.edu/about/
The Fisher Center for Business Analytics advances the creation of business value from data science. The Center pursues its vision through research, education, and accelerating the diffusion and adoption of analytics throughout all aspects of business and management. Their missions explore and design new data science applications, support data democratization, and establish the grounds for reasoned, wise, and inspired data governance.
For More on FCBA – https://fcba.berkeley.edu/
For More Information Contact:
Tanu Verma
Head of PR & Marketing Communications
marketing@affineanalytics.com
The post Affine becomes a new Fellow at the “Fisher Center For Business Analytics at Berkeley Haas” appeared first on Affine.
]]>The post Demand Forecasting Accuracy with AI & ML appeared first on Affine.
]]>The post Demand Forecasting Accuracy with AI & ML appeared first on Affine.
]]>The post Semantic Literature Search Powered by Sentence-BERT appeared first on Affine.
]]>Suppose you were given a challenge to pick out a horror novel from a small collection of books, without any prior information regarding these books. How would you go about this task in the most efficient way possible? The most appropriate strategy would be flicking through the books to figure out the theme based on its words/sentences/paragraphs. Another approach could be reading the reviews on the cover page for context.
This article discusses how we can use a pre-trained BERT model to accomplish a similar task. Kaggle recently released an Open Research Dataset Challenge called CORD-19 , with over 52,000 research articles on COVID-19, SARS-CoV-2, and other related topics. The problem statement was to provide insights on the “tasks” using this vast research corpus. The required solution must fetch all the relevant research articles based on questions user submits.
Our approach to finding the most relevant research articles (related to the task), was to compare the question with abstracts of all the research articles present. By finding the similarity score, we could easily rank the top-N articles. Comparing the question with the entire corpus is as easy as flicking through the small collection of novels to pick out the horror genre. This automation takes place by using Sentence-Transformers library, pre-trained BERT model and Spacy library
Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks, 2019 ACL paper by Nils Reimers and Iryna Gurevych mention the architecture, and advantages of Siamese and Triplet Network Structures, some of which are:
Methodology:
1. Install sentence-transformers and load a pre-trained BERT model. We have used ‘bert-base-nli-mean-tokens’ due to its high performance on STS benchmark dataset.
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('bert-base-nli-mean-tokens')
2. Vectorize/encode the abstracts of each article using pre-trained Bert embedding. Suppose the abstracts are contained in a list named ‘abstract’.
abstract_embeddings = model.encode(abstract)
The abstracts are encoded using BERT pre-trained embeddings and the shape would be (size of abstract list) rows × 768 columns.
3. Dump the abstract_embeddings as pickle.
with open("my.pkl", "wb") as f:
pickle.dump(abstract_embeddings, f)
4. Inference from the trained embeddings in real time.
i) Load the embedding file “my.pkl”.
with open("my.pkl", "rb") as f:
df = pickle.load(f)
ii) Encode the question into a 768-D embedding using step 1-2.
For e.g., the question “What do we know about COVID-19 risk factors?” would be represented by a 768 dimensional embedding.
iii) Compare the question with all the abstracts’ embeddings and find the cosine similarity to rank and give top-N results. As the question and the abstracts are in numerical form, this can be done easily using scipy function.
distances = scipy.spatial.distance.cdist([query_embedding], df, "cosine")[0]
This article discusses how to use pre-trained Sentence-BERT library for a downstream NLP task, which is to find relevant research articles based on user’s questions.
We can compare the question with the title or research body. Comparing the question with only the title could be less informative as the text-length of the title will be too small. Contrary to this, comparing the question with the research body requires heavy computations. Additionally, shrinking the huge research body to 768 dimensions will lead to a huge loss of information.
However, feel free to experiment with embeddings of the title and research body.
Your findings may be fascinating.
Reference(s):
https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge
https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge/tasks
https://github.com/UKPLab/sentence-transformers
https://github.com/UKPLab/sentence-transformers/blob/master/docs/pretrained-models/nli-models.md
https://www.aclweb.org/anthology/D19-1410.pdf
https://www.aclweb.org/anthology/D19-1410/
The post Semantic Literature Search Powered by Sentence-BERT appeared first on Affine.
]]>The post UNCOVERED! COVID-19 & CONSUMER BEHAVIOR appeared first on Affine.
]]>There is a conscious buying behavior centered around the most basic needs with people currently buying local and embracing digital commerce.
Will COVID-19 permanently change consumer behavior?
With global pandemic changing consumer sentiment, it becomes more important than ever to have an overview of the market.
Key Takeaways:
The post UNCOVERED! COVID-19 & CONSUMER BEHAVIOR appeared first on Affine.
]]>The post COVID-19: How can organizations survive successfully in current times? appeared first on Affine.
]]>We are all taking part in History with the Coronavirus pandemic bringing the world to a standstill. Managers and leaders across the Globe are new to handling work at home situations as organizations are forced to adapt to a new work culture.
Although a novelty for many, this arrangement is becoming increasingly popular. While the physical world is on hold, the digital world has become busier than ever.
How can companies make home offices a success? Has this become the new normal?
For more information, join Affine’s webinar with experts discussing:
1. The challenges people face while working from home and guidance on how to deal with it.
2. Why some companies thrive when others fail in times of crisis?
3. And what to expect when we finally resume our normal lives?
The post COVID-19: How can organizations survive successfully in current times? appeared first on Affine.
]]>The post Labor Optimization appeared first on Affine.
]]>In this case study, we will learn on how different analytical solutions provided to cut costs and increase sales volume of stores
The post Labor Optimization appeared first on Affine.
]]>The post Business Impacts of COVID-19 on Production & Manufacturing appeared first on Affine.
]]>The post Business Impacts of COVID-19 on Production & Manufacturing appeared first on Affine.
]]>The post Bayesian Theorem: Breaking it to simple using pymc3 Modelling appeared first on Affine.
]]>This article edition of Bayesian Analysis with Python introduced some basic concepts applied to the Bayesian Inference along with some practical implementations in Python using PyMC3, a state-of-the-art open-source probabilistic programming framework for exploratory analysis of the Bayesian models.
The main concepts of Bayesian statistics are covered using a practical and computational approach. The article covers the main concepts of Bayesian and Frequentist approaches, Naive Bayes algorithm and its assumptions, challenges of computational intractability in high dimensional data and approximation, sampling techniques to overcome challenges, etc. The results of Bayesian Linear Regressions are inferred and discussed for the brevity of concepts.
Introduction
Frequentist vs. Bayesian approaches for inferential statistics are interesting viewpoints worth exploring. Given the task at hand, it is always better to understand the applicability, advantages, and limitations of the available approaches.
In this article, we will be focusing on explaining the idea of Bayesian modeling and its difference from the frequentist counterpart. To make the discussion a little bit more intriguing and informative, these concepts are explained with a Bayesian Linear Regression (BLR) model and a Frequentist Linear Regression (LR) model.
Bayesian and Frequentist Approaches
The Bayesian Approach:
Bayesian approach is based on the idea that, given the data and a probabilistic model (which we assume can model the data well), we can find out the posterior distribution of the model’s parameters. For e.g.
In Bayesian Linear Regression approach, not only the dependent variable y, but also the parameters(β) are assumed to be drawn from a probability distribution, such as Gaussian distribution with mean=β^{T}X, and variance =σ^{2}I (refer equation 1). The outputs of BLR is a distribution, which can be used for inferring new data points.
The Frequentist Approach, on the other hand, is based on the idea that given the data, the model and the model parameters, we can use this model to infer new data. This is commonly known as the Linear Regression Approach. In LR approach, the dependent variable (y) is a linear combination of weights term-times the independent variable (x), and e is the error term due to the random noise.
Ordinary Least Square(OLS) is the method of estimating the unknown parameters of LR model. In OLS method, the parameters which minimize the sum of squared errors of training data are chosen. The output of OLS are “single point” estimates for the best model parameter.
Let’s get started with Naive Bayes Algorithm, which is the backbone of Bayesian machine learning algorithms. Here, we can predict only one value of y, so basically it is a point estimation
Naive Bayes algorithm for classification
Discussions on Bayesian Machine Learning models require a thorough understanding of probability concepts and the Bayes Theorem. So, now we discuss Bayes’ Algorithm. Bayes’ theorem finds the probability of an event occurring, given the probability of an already occurred event. Suppose we have a dataset with 7 features/attributes/independent variables (x_{1}, x_{2, }x_{3},…, x_{7}), we call this data tuple as X. Assume H is the hypothesis of the tuple belonging to class C. In Bayesian terminology, it is known as the evidence. y is the dependent variable/response variable (i.e., the class in classification problem). Then Mathematically, Bayes theorem is stated as :
Where:
As we can see, the posterior probability of H conditioned on X is directly proportional to likelihood times prior probability of class and is inversely proportional to the ‘Evidence’.
Bayesian approach for regression problem: Assumptions of Bayes theorem, given a sales prediction problem with 7 independent variables.
i) Each pair of features in the dataset are independent of each other. For e.g., feature x_{1} has no effect on x_{2}, & x_{2} has no effect on feature x_{7}.
ii) Each feature makes an equal contribution towards the dependent variable.
Finding the posterior distribution of model parameters is computationally intractable for continuous variables, we use Markov Chain Monte Carlo and Variational Inferencing methods to overcome this issue.
From Naive Bayes theorem (equation 3), posterior calculation needs a prior, a likelihood and evidence. Prior and likelihood are calculated easily as they are defined by the assumed model. As P(X) doesn’t depend on H and given the values of features, the denominator is constant. So, P(X) is just a normalization constant. We need to maximize the value of numerator in equation 3. However, the evidence (probability of data) is calculated as:
Calculating the integral is computationally intractable with high dimensional data. In order to build faster and scalable systems, we require some sampling or approximation techniques to calculate the posterior distribution of parameters given in the observed data. In this section, two important methods for approximating intractable computations are discussed. These are sampling-based approach. Markov-chain Monte Carlo Sampling (MCMC sampling) and approximation-based approach known as Variational Inferencing (VI). Brief introduction of these techniques are as mentioned below:
Prior Selection: Where is the prior in data, from where do I get one?
Bayesian modelling gives alternatives to include prior information into the modelling process. If we have domain knowledge or an intelligent guess about the weight values of independent variables, we can make use of this prior information. This is unlike the frequentist approach, which assumes that the weight values of independent variables come from the data itself. According to Bayes theorem:
Now that the method for finding posterior distribution of model parameters are being discussed, the next obvious question based on equation 5 is how to find a good prior. Refer [2] for understanding how to select a good prior for the problem statement. Broadly speaking, the information contained in the prior has a direct impact on the posterior calculations. If we have a more “revealing prior” (a.k.a., a strong belief about the parameters), we need more data to “alter” this belief. The posterior is mostly driven by prior. Similarly, if we have an “vague prior” (a.k.a., no information about the distribution of parameters), the posterior is much driven by data. It means that if we have a lot of data, the likelihood will wash away the prior assumptions [3]. In BLR, the prior knowledge modelled by a probability distribution is updated with every new sample (which is modelled by some other probability distribution).
Modelling using PyMC3 library for Bayesian Inferencing
Following snippets of code (borrowed from [4]), shows Bayesian Linear model initialization using PyMC3 python package. PyMC3 model is initialized using “with pm.Model()” statement. The variables are assumed to follow a Gaussian distribution and Generalized Linear Models (GLMs) used for modelling. For an in-depth understanding on PyMc3 library, I recommend Davidson-Pilon’s book [5] on Bayesian methods.
Fig. 1 Traceplot shows the posterior distribution for the model parameters as shown on the left hand side. The progression of the samples drawn in the trace for variables are shown on the right hand side.
We can use “Traceplot” to show the posterior distribution for the model parameters and shown on the left-hand side of Fig. 1. The samples drawn in the trace for the independent variables and the intercept for 1,000 iterations are shown on the right-hand side of the Fig 1. Two colours – orange and blue, represent the two Markov chains.
After convergence, we get the coefficients of each feature, which is its effectiveness in explaining the dependent variable. The values represented in red are the Maximum a posteriori estimate (MAP), which is the mean of the variable value from the distribution. The sales can be predicted using the formula:
As it is a Bayesian approach, the model parameters are distributions. Following plots show the posterior distribution in the form of histogram. Here the variables show 94% HPD (Highest Posterior Density). HPD in Bayesian statistics is the credible interval, which tells us we are 94% sure that the parameter of interest falls in the given interval (for variable x_{6}, the value range is -0.023 to 0.36).
We can see that the posteriors are spread out, which is an indicative of less data points used for modelling, and the range of values each independent variable can take is not modelled within a small range (uncertainty in parameter values are very high). For e.g., for variable x_{6}, the value range is from -0.023 to 0.36, and the mean is 0.17. As we add more data, the Bayesian model can shrink this range to a smaller interval, resulting in more accurate values for weights parameters.
When to use linear and BLR, Map, etc. Do we go Bayesian or Frequentist?
The equation for linear regression on the same dataset is obtained as:
If we see Linear regression equation (eq. 7) and Bayesian Linear regression equation (eq. 6), there is a slight change in the weight’s values. So, which approach should we take up? Bayesian or Frequentist, given that both are yielding approximately the same results?
When we have a prior belief about the distributions of the weight variables (without seeing the data) and want this information to be included into the modelling process, followed by automatic belief adaptation as we gather more data, Bayesian is a preferable approach. If we don’t want to include any prior belief and model adaptions, the weight variables as point estimates, go for Linear regression. Why are the results of both models approximately the same?
The maximum a posteriori estimates (MAP) for each variable is the peak value of the variable in the distribution (shown in Fig.2) close to the point estimates for variables in LR model. This is the theoretical explanation for real-world problems. Try using both approaches, as the performance can vary widely based on the number of data points, and data characteristics.
Conclusion
This blog is an attempt to discuss the concepts of Bayesian inferencing and its implementation using PyMC3. It started off with the decade’s old Frequentist-Bayesian perspective and moved on to the backbone of Bayesian modelling, which is Bayes theorem. Once setting the foundations, the concepts of intractability to evaluate posterior distributions of continuous variables along with the solutions via sampling methods viz., MCMC and VI are discussed. A strong connection between the posterior, prior and likelihood is discussed, taking into consideration the data available in hand. Next, the Bayesian linear regression modelling using PyMc3 is discussed, along with the interpretations of results and graphs. Lastly, we discussed why and when to use Bayesian linear regression.
Resources:
The following are the resources to get started with Bayesian inferencing using PyMC3.
[1] https://eigenfoo.xyz/bayesian-modelling-cookbook/
[2] https://github.com/stan-dev/stan/wiki/Prior-Choice-Recommendations
[3] https://stats.stackexchange.com/questions/58564/help-me-understand-
bayesian-prior-and-posterior-distributions
[4] https://towardsdatascience.com/bayesian-linear-regression-in-python-
using-machine-learning-to-predict-student-grades-part-2-b72059a8ac7e
[5] Davidson-Pilon, Cameron. Bayesian methods for hackers: probabilistic
programming and Bayesian inference. Addison-Wesley Professional, 2015.
The post Bayesian Theorem: Breaking it to simple using pymc3 Modelling appeared first on Affine.
]]>The post Defying the COVID-19 with an Unstoppable Work-Force appeared first on Affine.
]]>Manas Agrawal, Affine’s CEO, recently shared an email to his employees, urging them to stay healthy and work from home amidst the recent developments in COVID-19 situation.
Team,
I trust that you, your families/communities are safe and doing well this season. We acknowledge the unprecedented times we are in, owing to the constantly changing COVID-19 situation, and our hearts and thoughts go out to each and every one of you.
While we are affected by the impact of COVID-19 in all aspects of our lives, I am sad to tell you that things may get worse before they get better. With no manuals to guide us through this fast-changing workflow, please remember to have deep empathy and understanding of each other’s situation.
And as we travel through unchartered territories, I understand that some of you may feel that all this is a little unsettling and overwhelming. Remind yourselves to stay grounded with a sense of purpose and the importance of acting as a community in trying times like these.
We are working with the senior leadership teams to support you in the best ways possible, prioritizing your health and safety. Our resolve is to empower individuals as we will not be able to solve a challenge like this on our own. While technology has a significant role in accelerating progress for solutions to pandemics such as this, the private and public sectors will have to work together to turn the tide on COVID-19.
I’m not alone in being grateful for the exceptional work you are all doing for Affine. The management is noticing your efforts at every level. I want to congratulate everyone for successfully achieving this Work From Home scenario without any disruptions in your deliverables. Your diligence, self-motivation, and dedication in going the extra mile are admirable.
Remember to focus on what you can do to make the world a better place. Our collective efforts will make a difference beyond measure. Times ahead may get harder than ever, but remember that we are all in this together!
Keep your hopes up and continue the exceptional teamwork knowing that you are part of an Unstoppable Work-Force!
It will only be a matter of time before we emerge victorious to an era of wellbeing and development.
But until then, stay safe, stay healthy.
Warm Regards,
Manas Agrawal
CEO – Affine
The post Defying the COVID-19 with an Unstoppable Work-Force appeared first on Affine.
]]>