Loading Images from Multiple Folders along with their labels into an array - python

I am working on a multiclass image classification problem and there are 12 folders inside my training folder and I am trying to load all the images from these 12 folders along with their label in the numpy arrays both X and Y.
This is the code that I am using. I am able to get the images as an array, however I want to know how to get the corresponding labels as well. I'd appreciate the help.
This is the code that I am using.

Related

Is there a way to resize non-image files for CNN similarly to image-based examples?

I am working on a research project involving brain wave data. The goal is to classify (1,0) each "image." The problem is essentially an image classification problem, where I could use a CNN, but it's not clean at all like most CNN examples online. The files that I have are tsv's (each file is an individual trial from a patient), and I have stacked them all into one pickle file with each having the participant ID and trial ID as an additional column.
I want to feed them through a CNN, but almost examples online deal with equal-sized images. My data aren't of equal size, and they aren't images. I'm wanting to use PIL to make each file the same size, but is PIL even the correct way of doing so since I don't have image files?

Is there a method of aligning 2D arrays based on features much like Image Registration

I have two 2D arrays. One consist of reference data and the other measured data. While the matrices have the same shape the measured data will not be perfectly centered; meaning, the sample may not have been perfectly aligned with the detector. It could be rotated or translated. I would like to align the matrices based on the features much like image registration. I'm hoping someone can point me in the direction of a python package capable of this or let me know if opencv can do this for numpy arrays with arbitrary values that do not fit the mold of a typical .png or .jpg file.
I have aligned images using opencv image registration functions. I have attempted to convert my arrays to images using PIL with the intent being to use the image registration functions within opencv. If needed I can post my sample code but at this point I want to know if there is a package with functions capable of doing this.

Keras images with no subfolders

I am new to Deep Learning. I have this question: I am trying to train a network with this data. Everything is in one folder and labels are in a different mat file.
I understand that I can read the data with scipy.io. But how can I get train X in one folder? If I use the built in flow_from_directory it shows no images, because every class should have it's own folder.
How can I create X with only one folder? Now it shows Found 0 images belonging to 0 classes
There is just a folder with images. All images are in 1 folder. I mean there is no classes folder. With flow_from_directory you should have something like cars/mercedes, cars/bmw, cars/audi, but my data doesn't have subfolders.
So my question is there any other way to create X data?
Set classes to None and put all images into one subfolder of your image folder.
For example:
flow_from_directory(directory = "/path/to/your/images/", class_mode="None", …)
put your images into /path/to/your/images/data
The link you posted also shows a download link to "A devkit, including class labels for training images and bounding boxes for all images".
You'll find the information there that you need in order to transform your data set into the desired folder structure required for flow_from_directory().
From the README.md
-cars_meta.mat:
Contains a cell array of class names, one for each class.
-cars_train_annos.mat:
Contains the variable 'annotations', which is a struct array of length
num_images and where each element has the fields:
bbox_x1: Min x-value of the bounding box, in pixels
bbox_x2: Max x-value of the bounding box, in pixels
bbox_y1: Min y-value of the bounding box, in pixels
bbox_y2: Max y-value of the bounding box, in pixels
class: Integral id of the class the image belongs to.
fname: Filename of the image within the folder of images.

How to get number of images in NIfTi object? (nibabel)

I have a Nifti object generated from a directory of dicom files.
It seems that the Nifti should know how many frames it holds, but all I can find in the header info is the shape. The problem is, the shape is at times (num_images, x, y) and at times (x, y, num_images).
The only nibabel functions I found relevant where from the Ecat library. I am not familiar with ecat format, but I want my method to work for any nii file. I am working with the nibabel library.
Is there a way to retrieve the number of images in a Nifti file?
I'm guessing you're looking at fMRI, DTI or ASL data.
Say your 4D nii stack is called 'data.nii.'
Just go into that directory and do:
mri = nib.load('data.nii')
mri.shape
The fourth element you see will be the number of volumes. You can access it thusly: mri.shape[3] if you need it for some kind of purpose in your programs.
This works consistently for me. If your data are "stacked" in an inconsistent orientation, you are going to have to get fancy.
You could include checks based off of the dimensionality of your images. For example if you know that your images are 128x128x128, then you can go ahead and get whichever element of mri.shape isn't 128, but this approach is suboptimal for a few reasons.

How do I prepare data (images) for py-faster-rcnn classification training?

I am trying to train my own image classificator with py-faster-rcnn link using my own images.
It looks rather simple in the example here, but they are using some ready dataset (INRIA Person). Datasets are structured and cropped to sub-images (actually data sets there are both original images and cropped people images from them) and text notation of each image with coordinates of crops. Pretty straightforward.
Still I have no idea how this is done - do they use any sort of tool for this (I can hardly imagine some test lots of data are cropped and notated manually)?
Could anyone please suggest a solution for this one? Thanks.

Categories

Resources