Lesson 2 - Creating your own dataset from Google Images

Thank you Johannes. Appreciate your help.

Hey @mrfabulous1,
Ha - If you showed the pics to 3 machinists theyā€™d know straight away - Iā€™m not one - but grew up amongst them. Its funny - there were very few classification mistakes. It seems that the system struggled to differentiate individuals but was very good at classification.
Grinders all have a grinding wheel in-line with the moving bed, and a tray with ends to catch the waste. lathes have a horizontal axis, milling machines have a vertical axis and a tool-holder/chuck not a grinding disk and no ends on the tray to catch sparks/waste. But the rest of the bits and bobs are very similar between the mills and grinders. And all cats and dogs have ears and eyes and fur mostly :slight_smile:

Its very reassuring what you say. I feel encouraged to keep going!
Feature engineering must be the art.

Cheers, and many thanks!

ā€“me

1 Like

@mrfabulous1 - check this, I tried again with resnet50 on the filtered results. Pretty good i think. Must have been too lo-res for all that confusing detailā€¦

Cheersā€¦

1 Like

Hi banksiaboy well done!

It looks like a good step if one experiences this type of problem is to try a stronger/model.

Iā€™ll keep this in my repertoire.

Cheers mrfabulous1 :smiley: :smiley:

1 Like

Hi johannesstutz hope your having a jolly day!!

For a human maybe but not for an ai model :laughing: :laughing:
You could also try using an even bigger resnet model.

I would definitely use more images I always use a mininum of 200 per class for my first benchmark model.

I have added two links on feature engineering which I found quite helpful.

Have a jolly day :smiley: :smiley:

1 Like

Hi and thanks mrfabulous :slight_smile:

Iā€™ll keep experimenting with different models, augmentations, resolutions, ā€¦
I have around 400 images per category, maybe Iā€™ll add some more and see if it helps.

Regarding feature extraction, thank you for the links. It makes sense to me on tabular data. But Iā€™m not sure how to apply this in computer vision :smiley: For example, method 3 in the second link, edge detection. Isnā€™t that something that a CNN should figure out for itself, via learnt (or pretrained) kernels?

Hi

johannesstutz hope all is well!

The paper below is one that Jeremy uses. in one of the videoā€™s. I think its wonderful.

The paper above gives an insight into what CNNā€™s are doing. There may indeed be a layer that is highly correlated to the characteristic of lathes and grinders etc.

Currently whatever one does to improve your network, its a little like a dark art, in that unless your accuracy metric goes up or down one really doesnā€™t know much about which layers are being used the most. But I would postulate if you could apply this paper to your network and then make changes and see what actually happens. The results would be highly interesting.

I have seen people choose use a specific layer before they fine tune.

I wonder what the inside of your model looks like.


Image from above paper.

Cheers mrfabulous1 :smiley: :smiley:

1 Like

Hi,
Iā€™m a novice. Need some help please.

I have downloaded bear images from google, saved them in specific folders (black, grizzly & teddy). Renamed the files as blackbear1.jpg, blackbear2.jpg etc in the respective folders.

When running the below code:

np.random.seed(42)
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2, ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)

I am getting 2 issues (IndexError and Exception) listed below.

IndexError : index 0 is out of bounds for axis 0 with size 0

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last) in

    1 np.random.seed(4) 

----> 2 data = ImageDataBunch.from_folder(path, train =".", valid_pct=0.2, ds_tfms = get_transforms (), size=224, num_workers=4).normalize(imagenet_stats)

Exception: Canā€™t infer the type of your targets. Itā€™s either because your data source is empty or because your labelling function raised an error.

Kindly suggest what could be the problem.

Hey harsh did you ever find a solution to this? I am having the same issue.

Hi all, finally got my first ML web app up and live and wanted to share some of my experience briefly. The app and model themselves arenā€™t really very special, but Iā€™ll share them here.

(Resnet 34 model trained to identify if a mountain is Mt. Rainier [Washington State], Mt. Hood [Oregon], or Mt. Fuji [Japan]) - Give it a try!
https://mountainid-test.onrender.com/
https://web-app-early.wl.r.appspot.com/

For me, the model building was straightforward. I was able to work through the lesson 1 and 2 notebooks without issue to download images and train my model. The accuracy was ā€˜okā€™ at 80% and I didnā€™t really focus much on improving it beyond the steps in the lesson. I then both saved (.pth) and exported (.pkl) my model - this becomes important later.

From there, I basically followed the ā€˜Productionā€™ instructions for the Google App Engine and I found them to be again mainly straightforward. I hit a big snag once I started trying to deploy the model though. I kept getting a massive error with tons of lines of code as it tried to run script.py. I did a bunch of debugging including:

  • Deploying on Render (didnā€™t work)
  • Trying to run the original example script.py (that worked)
  • Checking that my model_file_url worked by typing into my browser and seeing if it downloaded directly (it did)

I was starting to sweat a little bit and frantically search through the forums at this point. My eureka moment was when I downloaded the model for the original example from Dropbox and it came back as ā€œstage-2.pth.ā€ That is when I realized that I was using the export .pkl instead of the .pth files.

Did I miss something in the instructions? I was under the impression that we should be using the exported model instead of the saved one.

In any case, that cleared things right up and my web app was up and running. I know this was a long post/story but Iā€™m hoping that my experience can help give someone a kickstart if needed.

1 Like

Iā€™m going to have save this thread because Iā€™m exactly here and decided to take a breather and see if I know what Iā€™m doing in lesson 2 before venturing on making the application. Thanks for all the tips though and I hope to make it as fancy as yours!

Andy

Hi! How did you do highlighted regions in the images of airplanes?

The code below can be used, but with some human interaction. This code is somewhat slow but returns a more complete list. Also, the code below gets the original image rather than the version stored in Google, which may be lower res or just a thumbnail. To begin with, make sure your image search results do not exceed the minimum returned by Google by default as the code takes a while to run.

So, given the search: 360 digger -toy -book -dog -"t-shirt" -leurre -hat -"total solutions" -its -antennas -"metal working" -compressor -drill copy and paste the lines below into the console.

Hereā€™s the search for a ride-on roller -toy -battery -skates -"roller blades" -bicycle -coaster

// set up the observer
function hrefTest(mutationList, observer) {
	mutationList.forEach( (mutation) => {
		if( mutation.attributeName === 'href' ) {
			let thisHref = mutation.target.href.split('imgurl=')[1].split('&imgrefurl')[0];
			urls.push(decodeURIComponent(thisHref));
			console.log(decodeURIComponent(thisHref));
		}
	});
}

const observerOptions = {
	childList: false,
	attributes: true,
	subtree: false
}
const observer = new MutationObserver(hrefTest)
let urls = Array();
let anchors = document.querySelectorAll('a.islib');

anchors.forEach((a) => {
	a.addEventListener('click', (event) => {event.eventTarget.preventDefault()}, {
		capture: false,
		passive: true
	});
	observer.observe(a, observerOptions);
});

Next, copy and paste the code below.

// click every image
document.querySelectorAll('a.islib').forEach((elem) => {
	elem.click();
});

The code above will take time to process. On a page result of 100 images it can take 2 minutes or more. When itā€™s done (when all the images have finished loading), copy and paste the code below to get the final CSV.

window.open('data:text/csv;charset=utf-8,' + escape(urls.join('\n')));