GithubHelp home page GithubHelp logo

Preprocessing images about kerasgen HOT 7 CLOSED

ma7555 avatar ma7555 commented on May 30, 2024
Preprocessing images

from kerasgen.

Comments (7)

ma7555 avatar ma7555 commented on May 30, 2024

Hello @jaimerodric ,

Sorry for the late response. As the output is a normal tf.data.Dataset you can use the apply function normally after creating the dataset from the generator.

from kerasgen.

jaimerodric avatar jaimerodric commented on May 30, 2024

@ma7555
Thanks for your response! That's a smart solution. If I am not wrong, the images are loaded as RGB, right? I want to confirm this because when testing, if I load images with opencv, they are in BGR form and should I convert it ro RGB?

I am trying to train a network from scratch and I am struggling, I do not know if it is because working with only 200k images, the generator, the network...

from kerasgen.

ma7555 avatar ma7555 commented on May 30, 2024

The images are loaded in RGB as tf.Tensor, to use a preprocessing function you need to use the apply method I mentioned but make sure all the transformations are done using tf ops and not numpy.
If you need to use numpy or other pythonic functions please refer to tf.numpy_function and tf.function

from kerasgen.

jaimerodric avatar jaimerodric commented on May 30, 2024

@ma7555
Thanks again for the response. What margin have you tested that is the better for training? Because the TripletSemiHardLoss, it is by default established on 1, but from my point of view it does not make sense when there is a normalization L2 at the end of the network (normalized output of 1)

from kerasgen.

ma7555 avatar ma7555 commented on May 30, 2024

I have not experimented with changing the margin. But keeping it default worked well for me.

from kerasgen.

jaimerodric avatar jaimerodric commented on May 30, 2024

Hi again @ma7555 !
I am struggling applying the preprocessing function. I have implemented one that is like this:

def pre_process_facenet(dataset):
x_images = []
for ret in dataset:
# standardize pixel values across channels (global)
mean, std = ret.mean(), ret.std()
ret = (ret - mean) / std
x_images.append(ret)
return np.array(x_images)

train_ds = balanced_image_dataset_from_directory(
directory, num_classes_per_batch=5,
num_images_per_class=5, image_size=(160, 160),
seed=6, validation_split=0.2, subset='training',
safe_triplet=True)

But when using apply on the dataset generated with kerasgen I got some errors
train_ds = train_ds.apply(tf.numpy_function(pre_process_facenet, train_ds, tf.float32))
ValueError: could not broadcast input array from shape (25,160,160,3) into shape (25,)

What I am doing wrong? I want to apply pre_process_facenet in train_ds and then into the fit method of TF

from kerasgen.

simkarwin avatar simkarwin commented on May 30, 2024

mimo-Keras package (https://pypi.org/project/mimo-keras/) can help you to create your pipeline without additional coding

from kerasgen.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.