Hi and welcome back.
So in this section, we'll take a look at another medical data application where we'll be taking a look
at X-rays, chest X-rays to detect if pneumonia is present.
And we're going to use to be used to do this.
So all the time we're using GPUs, sometimes CPU's.
Now we're going to use something called Google's TP Use, which our Tensor Processing Units.
So open Notebook 70 and we'll get started.
So firstly, again, this came from the Keros official tutorial site, and it's prepared by Amy McEwen
Young.
So let's get started with this lesson.
So firstly, let's basically just load the libraries here, and we're going to actually start using
the TPU is here.
So by using these functions here, we're going to get the number of TPA calls that we have and you can
see we have eight cores available.
Number four, because means number of calls here.
Well, to have one tip, you could turn on both with his picture.
Sorry to be used to look.
So basically one tip you would it, which is effectively said no, we just set some parameters here,
as well as a class lens.
And now we load the data.
So this data we are using from so and we can take a look at that source here is basically some medical
data repository that talks about how to use deep learning for medical practices.
It's a very good read, actually, if you're interested in the health sector of computer vision, so
I would encourage you to encourage you to check it out.
So now let's take a look at so let's count how much normal, healthy chest X-rays there are and how
much pneumonia.
And you can see there a lot more pneumonia X-rays in this count by maybe an order of almost at least
twice, almost three times.
Sorry, I should say, of the normal images, normal lung scans here.
So we do have to correct for those class imbalances a bit afterward.
But for now, let's create some hope of functions that we'll be using later on.
And now we can split the data into test and validation data sets here, and we just load the format
from other data.
That's right.
The format of the test data as well.
And now we can visualize the data.
So let's take a look at this function that visualizes, takes a batch and returns it so we can visualize
it during this period of training history.
And this is the function of returns that batch of data using the item itself.
You would see you get a batch of data there.
And now this is a function that shows the batch of data here so we can take a look and you can see what
pneumonia X-ray scans look like and what normal chest x ray scans look like.
And as you can see, there's not much normal is just one two three four for normal lung scans and a
lot more pneumonia scans.
And you can see it's very hard for me as a layperson who is not an X-ray technician to understand what's
the difference between a pneumonia lung and a normal lung.
You can kind of see, at least to me, the normal lungs tend to look smaller.
Except for this one, I'm not sure.
I'm honestly not sure.
Maybe, maybe it's to do with the clarity of how the deeper the blacks look.
Perhaps, but then again, that's not all.
That's true, so I'm honestly not sure what they're looking for.
Maybe deep learning can pick it up.
So now let's build on CNN.
So this creates a building block, functions here to block dense block, and we just create a model.
And you can see this model is just a simple model of convolutional is some dense blocks at the end,
pretty much a standard video type network.
And here we correct for the class imbalance as well.
So you can give we give each class a width and then we start treating the model.
So let's take a look at the training section here.
So just to final check points at our initial learning rate to get a listing of its schedule and then
now we can start compiling the final metrics and start treating to model finally.
So you can see trends per relatively quickly and then stop 779 epochs.
So that's because it probably reached the early stopping threshold and you can see your validation.
Lewis was pretty much all over the place at that point, but the accuracy was ninety seven percent and
the precision I'm sorry and record is actually quite good, as well as a very good scores, I must say.
So now let's visualize the model performance as well.
You can see the scores going up as e-books go, as well as the loss going down.
So actually, we are surpassing 95 percent, I believe.
Then we get that 97 percent, actually, although sometimes we're at ninety eight as well.
So that's.
Good.
So, no, this is a prediction here.
This image is 28 percent probability of it being normal and 71 for it being pneumonia.
And apparently this was a normal lung.
If I'm not mistaken, maybe you can try another sample because this probably should not have.
OK, there we go.
So that actually wasn't the correct by coincidence of incorrect classification.
So this one, the network says it's 99 percent normal and it actually is normal.
So that's pretty good.
So that's it for this lesson.
It's actually a very good lesson if you wanted to start learning about medical data.
So I would encourage you to read that link above.
And that's it for this lesson.
Hope you enjoyed it.
Thank you for watching.