Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Ask questions about projects relating to: biology, biochemistry, genomics, microbiology, molecular biology, pharmacology/toxicology, zoology, human behavior, archeology, anthropology, political science, sociology, geology, environmental science, oceanography, seismology, weather, or atmosphere.

Moderators: AmyCowen, kgudger, bfinio, MadelineB, Moderators

Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

I NEED HELP!! I was doing the code, and when I run code block 2A, where I view the images, it doesn't work! I keep getting this error: InvalidArgumentError Traceback (most recent call last)
<ipython-input-19-4d7074ac3861> in <cell line: 12>()
10 file_pattern = glob.glob ("/content/drive/MyDrive/tick_identification/data/A. americanum/*.jpg")
11 print(file_paths)
---> 12 dataset = tf.data.Dataset.list_files(file_pattern)
13 dataset = dataset.map(preprocess_fn)
14 dataset = dataset.batch(5) # Fetch 5 images at a time

2 frames
/usr/local/lib/python3.10/dist-packages/tensorflow/python/ops/control_flow_assert.py in Assert(condition, data, summarize, name)
100 xs = ops.convert_n_to_tensor(data)
101 data_str = [_summarize_eager(x, summarize) for x in xs]
--> 102 raise errors.InvalidArgumentError(
103 node_def=None,# Define a simple preprocessing function
def preprocess_fn(file_path):
image = tf.io.read_file(file_path)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.resize(image, [224, 224])
return image

# Create a dataset from image files
# Use glob to match files with different extensions
file_paths = glob.glob ("/content/drive/MyDrive/tick_identification/data/A. americanum/*.jpg")
print(file_paths)
dataset = tf.data.Dataset.list_files(file_pattern)
dataset = dataset.map(preprocess_fn)
dataset = dataset.batch(5) # Fetch 5 images at a time

# Create an iterator
iterator = iter(dataset)

# Fetch a batch of images
image_batch = next(iterator)

# Display the images side by side
plt.figure(figsize=(15, 5)) # Adjust the figure size as needed

for i in range(image_batch.shape[0]):
plt.subplot(1, image_batch.shape[0], i + 1) # 1 row, number of images columns
plt.imshow(image_batch.numpy().astype("uint8"))
plt.axis('off')

plt.show()
104 op=None,

InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true. Summarized data: b'No files matched pattern: '

I really need help! the slideshow is due today and I need the data, ASAP. This is the code I have:

# Define a simple preprocessing function
def preprocess_fn(file_path):
image = tf.io.read_file(file_path)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.resize(image, [224, 224])
return image

# Create a dataset from image files
# Use glob to match files with different extensions
file_paths = glob.glob ("/content/drive/MyDrive/tick_identification/data/A. americanum/*.jpg")
print(file_paths)
dataset = tf.data.Dataset.list_files(file_pattern)
dataset = dataset.map(preprocess_fn)
dataset = dataset.batch(5) # Fetch 5 images at a time

# Create an iterator
iterator = iter(dataset)

# Fetch a batch of images
image_batch = next(iterator)

# Display the images side by side
plt.figure(figsize=(15, 5)) # Adjust the figure size as needed

for i in range(image_batch.shape[0]):
plt.subplot(1, image_batch.shape[0], i + 1) # 1 row, number of images columns
plt.imshow(image_batch.numpy().astype("uint8"))
plt.axis('off')

plt.show()

Somehow it just doesn't work. PLEASE HELP MEEEEEE!!!!!!!!!!!!!!!!!
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Also this is a student.
bfinio
Expert
Posts: 964
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Lead Staff Scientist, Science Buddies
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by bfinio »

Hi,

We just tried running the code again and are unable to reproduce the error. The error message you're getting might indicate that your image files are missing or not in the right place. Have you completed this step in the procedure before trying to run the code?

"In the 'tick_identification' folder you uploaded earlier, there is a ‘data’ folder inside. Inside of the 'data' folder you will find three subfolders named A. americanum, D. variabilis, and I. scapularis. Download at least 50 images for each tick species from iNaturalist by right-clicking on the image and selecting ‘Save image as’ and upload them to the corresponding folder in your Google Drive."
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Thank you for your answer! When I click the link on science buddies to download and extract the file, it doesn't give me just one file. It gives me two: tick_identification (without me even extracting it) and it says data. I dragged both of those into My Drive, and put all the photos in. I think it's right but... I have no clue. Also can you please share your results?
bfinio
Expert
Posts: 964
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Lead Staff Scientist, Science Buddies
Project Question: Expert
Project Due Date: n/a
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by bfinio »

Hi - we provide background information and procedures for projects but we are unable to share results. Can you compare your Google Drive directory to what's shown in the project video here:

https://youtu.be/dk4Bg0dV5-w?si=xofLnaC8o_3d8fMf&t=119

It should be My Drive > tick_identification, with the "data" folder and the tick_identification.ipynb file. You then upload your images into the species subfolders in the "data" folder.

Based on your description, it sounds like you might have uploaded the data folder directly to My Drive, instead of uploading it inside the tick_identification folder, which might be causing the problem because the program cannot find the files where it's being told to look.
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

This seems to always be the problem:
Attachments
Screenshot 2025-01-06 153819.png
Screenshot 2025-01-06 153819.png (94.82 KiB) Viewed 9613 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

It's okay if you can't share results. I'm doing everything the video says. I don't know what's happening to the code.
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Can you confirm that you ran all of the steps in the first part of the notebook, which includes mounting the Google drive for use in colab. (There are steps there to allow the connection to drive that you have to approve.) In colab, this is a step under the Importing Libararies section. Make sure you've run this cell: from google.colab import drive -- without an error.

To make sure you've run the previous blocks, you can be positioned in cell 2 and use Runtime / Run Before.

You mentioned you are following the video. I would suggest also using the written directions as you go through the steps.

Amy
Science Buddies
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

(sorry for so many questions) Before I dragged the two files (like I said, both are seperate, there is no ONE folder when I download the link in science buddies), I made a new folder and name it tick_identification. I don't the link in science buddies could ever work as just one folder for me, and I don't know why.
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Thanks again for the reply! Yes, all code blocks before this one works.
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

I think the problem is with the mounting/location of the folder on your drive. (I can generate the same error you had if I have the wrong folder specified OR if the directories that should have images are empty.)

I'm not sure what you are describing with your folder/files.
Regardless of how you get at it, you should have a folder on your drive named tick_identifcation. Within that, you have tick_identification and a folder named data. Within the dat folder, there are three subfolders.

When you download the zip, those folders are empty.

The code won't run until you add images to the folders (as described in the project).

So to make sure you are set up, you want to be sure you see the folder with the .ipynb file and the data folder. Within that data folder, there are three other folders, into which you will place the images you gather.

Can you doublecheck that you have that structure (and have images in the folders)? The code in the early step where you mount the drive and the path to the images in step 2 all have to be properly pointing at the same location.

Can you show a screenshot of your drive with the files and of this step in your notebook: (my image attachments are not working) -- show a screenshot where you see this (in the section about step 2):

from google.colab import drive
drive.mount('/content/drive', force_remount=True)
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

In the written directions, you need to make sure you do this:

2. In the 'tick_identification' folder you uploaded earlier, there is a ‘data’ folder inside. Inside of the 'data' folder you will find three subfolders named A. americanum, D. variabilis, and I. scapularis. Download at least 50 images for each tick species from iNaturalist by right-clicking on the image and selecting ‘Save image as’ and upload them to the corresponding folder in your Google Drive.

I've set up the notebook again today, and I generate the error you had when I have no images. When I make sure the drive is mounted, and I have images in all folders, blocks 2A, 2B, and 2C run properly in colab.


Had you gone through the process of finding and saving your images?

(Knowing this will help us know if the directions were clear.)

Amy
Science Buddies
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Okay. I'll show you what I mean by my folders/files thing.
Step 1) I click on the link in science buddies
Step 2) This is what I always see (1st picture)

The second picture is the mounted drive.
Attachments
Screenshot 2025-01-06 165030.png
Screenshot 2025-01-06 165030.png (45.73 KiB) Viewed 9590 times
Screenshot 2025-01-06 164637.png
Screenshot 2025-01-06 164637.png (226.07 KiB) Viewed 9590 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

I have uploaded 50 images into their respective folders. As you can see in the screenshot I took, there is no "one folder". It's just two and I go to google drive and make a new folder in my drive and name it tick_identification. It does have data, and three separate folders: a. americanum, d. variabilis, and i. scapularis. Maybe the problem is that I'm making and naming a folder and it can't identify it?
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Yes, I have found all of my images on iNaturalist and saved the image.
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Okay - Thank you for confirming that you have saved the images to the three subfolders.

Can you make sure that the folder you have everything in on Google Drive is JUST called tick_identification? I see a (3) after that in your screenshot. (I'm also trying to make sure these are not just on your hard drive, that they have been moved to Google Drive.)

To run the code, you need a tick_identification folder in Google drive (at the main level of your drive) with the .ipynb file and the data folder (and its subfolders) in it.

The path in 2.A/B/C all reference those subfolders where the code looks for the images.

Again, doublecheck that your folder doesn't have any other info in the name.

(These files/folders have been uploaded to Google drive, right? These are not just sitting on your personal computer? I can't tell from the screenshot. The code will be looking for them in Google Drive, which you've mounted and directed the code to in the subsequent steps. It won't be looking at your hard drive.)
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Hi -

Here's a screenshot showing my files for this project sitting in Google Drive.
drive.png
drive.png (44.66 KiB) Viewed 9569 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Yes, the files are uploaded to my google drive, not my personal computer. I did try deleting all of the other tick folders, but it doesn't work (meaning if I open the data folder, it says no preveiw available). Is there any other problem? I'm sorry if I'm holding you up with my questions (I don't want to disturb you). Thank you again! (I saw your screenshot just now and that is what my page looks like :)
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

I'm happy to help. The problem definitely seems related to how the files are sitting in drive for you. It's hard to tell without being able to see them.

Can you please show a screenshot (like mine) showing the tick_identification folder on drive. And then a second screenshot showing that the subfolders are inside the data folder and then another screenshot of at least one of those subfolders showing that images are inside?

Amy
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

This is what I have as well:
Attachments
Screenshot 2025-01-06 181239.png
Screenshot 2025-01-06 181239.png (67.04 KiB) Viewed 9563 times
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Great. Can I see the other two screenshots -- the data folder contents and then one of the others with images? I'm glad to see this one!

When you opened the .ipynb file, this is the file you used, doubleclicked the file from within Google Drive to open it?

Amy
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Here is a screenshot of what happens when there are no images in the specified folder. I think this is the error you saw earlier. This is why I am having you go back through these steps.

One other thing to mention is that you may find you have to run the first steps again after you step away for a bit and come back. (I do. When my runtime disconnects, I do have to import and remount again. So you might redo those each time right now as you continue to troubleshoot.)

A confirmed error with zero images in the specified folder for step 2.A
tick-noimages.png
tick-noimages.png (110.87 KiB) Viewed 9559 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

My screenshots aren't working anymore for some reason. But it works, I know it.
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

There is no yellow box at all when I run my code, but I get the same error message. It works now.
Attachments
Screenshot 2025-01-06 183835.png
Screenshot 2025-01-06 183835.png (112.06 KiB) Viewed 9549 times
Screenshot 2025-01-06 183736.png
Screenshot 2025-01-06 183736.png (56.49 KiB) Viewed 9549 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

To clarify, the code doesn't work. I was talking about the screenshots.
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Okay - I think that's the problem. The line in the code is looking for files that are either .jpg or .png

Your files are named with .jpeg extension

To verify this is the problem, you could rename just one of the files to .jpg extension and run the cell.

If ALL of the files you saved are .jpeg files, you can try changing this line of code so that it looks at .jpeg files (instead of the jpg/png -- you'll see I added a # on the original line to comment it out for the moment and pasted in a new line that I changed to .jpeg):
jpeg.png
jpeg.png (33.57 KiB) Viewed 9543 times
(If this solves the problem for the files you have, you'll need to repeat the extension change for blocks 2B and 2C)


(The yellow boxes are just me highlighting the section I am trying to point out.)
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Thank you so much!!! It works!! I truly appreciate your time and effort for helping me!!
amyCC
Site Admin
Posts: 398
Joined: Wed Apr 01, 2020 4:02 pm
Occupation: Moderator
Project Question: *
Project Due Date: *
Project Status: Not applicable

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by amyCC »

Great! I'm so glad we were able to sort it out. I'm sorry it took so long -- but it took seeing your photo of your files to detect what was wrong.

Good luck finishing up your project. I hope it goes well, and we would love to hear about it.

Amy
Science Buddies
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Hey amyCC! I was just wondering if you could help me with another error in the code. This is the problem and error:
Attachments
Screenshot 2025-01-20 144530.png
Screenshot 2025-01-20 144530.png (29.61 KiB) Viewed 9326 times
Screenshot 2025-01-20 144515.png
Screenshot 2025-01-20 144515.png (55.18 KiB) Viewed 9326 times
Mrusia
Posts: 30
Joined: Mon Jan 06, 2025 8:32 am
Occupation: Parent

Re: Use Machine Learning to Identify Lyme Disease-Transmitting Ticks

Post by Mrusia »

Code blocks 2D, 4, and 5 don't work. (but code block 7 doesn't either)
Post Reply

Return to “Grades 6-8: Life, Earth, and Social Sciences”