pdfcoffee
Chapter 5Then the two feature vectors (one for the image, and one for the text) are combinedinto one joint vector that is provided as input to a dense network to produce thecombined network:# combine the encoded question and visual modelmerged = layers.concatenate([encoded_question, visual_model])# attach a dense network at the endoutput = layers.Dense(1000, activation='softmax')(merged)# get the combined modelvqa_model = models.Model(inputs=[image_input, question_input],outputs=output)vqa_model.summary()For instance, if we have a set of labeled images, then we can learn what the bestquestions and answers are for describing an image. The number of options isenormous! If you want to know more, I suggest that you investigate Maluuba,a start-up providing the FigureQA dataset with 100,000 figure images and1,327,368 question-answer pairs in the training set. Maluuba has been recentlyacquired by Microsoft, and the lab is advised by Yoshua Bengio, one of the fathersof deep learning.In this section, we have discussed how to implement VQA. The next section is aboutstyle transfer: a deep learning technique used for training neural networks to createart.Style transferStyle transfer is a funny neural network application that provides many insightsinto the power of neural networks. So what exactly is it? Imagine that you observea painting made by a famous artist. In principle you are observing two elements:the painting itself (say, the face of a woman, or a landscape) and something moreintrinsic, the "style" of the artist. What is the style? That is more difficult to define,but humans know that Picasso had his own style, Matisse had his own style, andeach artist has his/her own style. Now, imagine taking a famous painting of Matisse,giving it to a neural network, and letting the neural network repaint it in Picasso'sstyle. Or imagine taking your own photo, giving it to a neural network, and havingyour photo painted in Matisse's or Picasso's style, or in the style of any other artistthat you like. That's what style transfer does.[ 165 ]
Advanced Convolutional Neural NetworksFor instance, go to https://deepart.io/ and see a cool demo as shown in thefollowing image, where DeepArt has been applied by taking the "Van Gogh"style as observed in the Sunflowers painting and applying it to a picture of mydaughter Aurora:Now, how can we define more formally the process of style transfer? Well, styletransfer is the task of producing an artificial image x that shares the content ofa source content image p and the style of a source style image a. So, intuitivelywe need two distance functions: one distance function measures how different thecontent of two images is, L content, while the other distance function measures howdifferent the style of two images is, L style. Then, the transfer style can be seen as anoptimization problem where we try to minimize these two metrics. As in Leon A.Gatys, Alexander S. Ecker, Matthias Bethge [7], we use a pretrained network toachieve style transfer. In particular, we can feed a VGG19 (or any suitable pretrainednetwork) for extracting features that represent images in an efficient way. Now weare going to define two functions used for training the network: the content distanceand the style distance.Content distanceGiven two images, p content image and x input image, we define the contentdistance as the distance in the feature space defined by a layer l for a VGG19 networkreceiving the two images as an input. In other words, the two images are representedby the features extracted by a pretrained VGG19. These features project the imagesinto a feature "content" space where the "content" distance can be convenientlycomputed as follows:[ 166 ]
- Page 149 and 150: Convolutional Neural NetworksIn oth
- Page 151 and 152: Convolutional Neural NetworksThen w
- Page 153 and 154: Convolutional Neural NetworksHoweve
- Page 155 and 156: Convolutional Neural NetworksPlotti
- Page 157 and 158: Convolutional Neural NetworksIn gen
- Page 159 and 160: Convolutional Neural NetworksOur ne
- Page 161 and 162: Convolutional Neural NetworksThese
- Page 163 and 164: Convolutional Neural NetworksSo, we
- Page 165 and 166: Convolutional Neural NetworksEach i
- Page 167 and 168: Convolutional Neural NetworksVery d
- Page 169 and 170: Convolutional Neural NetworksRecogn
- Page 171 and 172: Convolutional Neural NetworksIf we
- Page 173 and 174: Convolutional Neural NetworksRefere
- Page 175 and 176: Advanced Convolutional Neural Netwo
- Page 177 and 178: Advanced Convolutional Neural Netwo
- Page 179 and 180: Advanced Convolutional Neural Netwo
- Page 181 and 182: Advanced Convolutional Neural Netwo
- Page 183 and 184: Advanced Convolutional Neural Netwo
- Page 185 and 186: Advanced Convolutional Neural Netwo
- Page 187 and 188: Advanced Convolutional Neural Netwo
- Page 189 and 190: Advanced Convolutional Neural Netwo
- Page 191 and 192: Advanced Convolutional Neural Netwo
- Page 193 and 194: Advanced Convolutional Neural Netwo
- Page 195 and 196: Advanced Convolutional Neural Netwo
- Page 197 and 198: Advanced Convolutional Neural Netwo
- Page 199: Advanced Convolutional Neural Netwo
- Page 203 and 204: Advanced Convolutional Neural Netwo
- Page 205 and 206: Advanced Convolutional Neural Netwo
- Page 207 and 208: Advanced Convolutional Neural Netwo
- Page 209 and 210: Advanced Convolutional Neural Netwo
- Page 211 and 212: Advanced Convolutional Neural Netwo
- Page 213 and 214: Advanced Convolutional Neural Netwo
- Page 215 and 216: Advanced Convolutional Neural Netwo
- Page 217 and 218: Advanced Convolutional Neural Netwo
- Page 219 and 220: Advanced Convolutional Neural Netwo
- Page 221 and 222: Advanced Convolutional Neural Netwo
- Page 223 and 224: Advanced Convolutional Neural Netwo
- Page 226 and 227: GenerativeAdversarial NetworksIn th
- Page 228 and 229: [ 193 ]Chapter 6Eventually, we reac
- Page 230 and 231: [ 195 ]Chapter 6Next, we combine th
- Page 232 and 233: Chapter 6And handwritten digits gen
- Page 234 and 235: Chapter 6Figure 1: Visualizing the
- Page 236 and 237: Chapter 6The resultant generator mo
- Page 238 and 239: Chapter 6Figure 4: A summary of res
- Page 240 and 241: Chapter 6def train(self, epochs, ba
- Page 242 and 243: Chapter 6The preceding images were
- Page 244 and 245: Chapter 6Another interesting paper
- Page 246 and 247: Chapter 6To elaborate, let us say t
- Page 248 and 249: Chapter 6Figure 7: The architecture
Chapter 5
Then the two feature vectors (one for the image, and one for the text) are combined
into one joint vector that is provided as input to a dense network to produce the
combined network:
# combine the encoded question and visual model
merged = layers.concatenate([encoded_question, visual_model])
# attach a dense network at the end
output = layers.Dense(1000, activation='softmax')(merged)
# get the combined model
vqa_model = models.Model(inputs=[image_input, question_input],
outputs=output)
vqa_model.summary()
For instance, if we have a set of labeled images, then we can learn what the best
questions and answers are for describing an image. The number of options is
enormous! If you want to know more, I suggest that you investigate Maluuba,
a start-up providing the FigureQA dataset with 100,000 figure images and
1,327,368 question-answer pairs in the training set. Maluuba has been recently
acquired by Microsoft, and the lab is advised by Yoshua Bengio, one of the fathers
of deep learning.
In this section, we have discussed how to implement VQA. The next section is about
style transfer: a deep learning technique used for training neural networks to create
art.
Style transfer
Style transfer is a funny neural network application that provides many insights
into the power of neural networks. So what exactly is it? Imagine that you observe
a painting made by a famous artist. In principle you are observing two elements:
the painting itself (say, the face of a woman, or a landscape) and something more
intrinsic, the "style" of the artist. What is the style? That is more difficult to define,
but humans know that Picasso had his own style, Matisse had his own style, and
each artist has his/her own style. Now, imagine taking a famous painting of Matisse,
giving it to a neural network, and letting the neural network repaint it in Picasso's
style. Or imagine taking your own photo, giving it to a neural network, and having
your photo painted in Matisse's or Picasso's style, or in the style of any other artist
that you like. That's what style transfer does.
[ 165 ]