Code Monkey home page Code Monkey logo

Comments (2)

rocksyne avatar rocksyne commented on August 16, 2024

Try this tool from the tensorflow library.

tf.data.Dataset.from_generator

It will help use a generator function to load data in batches. I am providing a pseudocode example below.

# now the generator function
def data_generator(original_data:list=None,batch_size:int=10)->list:

	# make sure the input data is not none
	if original_data is None:
		sys.exit("Input data invalid!")

	#we need to run this forever
	while 1:

		# run a for loop to be able to fetch the data in batches
		for batch in range(0,len(original_data),batch_size):
			data = original_data[batch:batch+batch_size] # fetch bacthes
			
			# I am not sure if this should be a numpy array
			# but if it should, please use the appropriate type casting
			# data = np.array(data).astype(np.float32) --> this is an example
			# Find your appropriate casting and set it as such

			# yield this current batch of data
			yield data


"""
H0w to use this in your code
-------------------------------------------------

import tensorflow as tf
from data_generator import data_generator

custom_genenerator = data_generator(parameter_1, optional_param_2)

dataset = tf.data.Dataset.from_generator(custom_genenerator,(tf.float32, tf.int16))
iterator = dataset.make_one_shot_iterator()

x,y = iterator.get_next()



Check the following references for explanation
--------------------------------------------------
Ref: 
https://sknadig.me/TensorFlow2.0-dataset/
https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator

"""

from c3d-tensorflow.

Wei-i avatar Wei-i commented on August 16, 2024

Try this tool from the tensorflow library.

tf.data.Dataset.from_generator

It will help use a generator function to load data in batches. I am providing a pseudocode example below.

# now the generator function
def data_generator(original_data:list=None,batch_size:int=10)->list:

	# make sure the input data is not none
	if original_data is None:
		sys.exit("Input data invalid!")

	#we need to run this forever
	while 1:

		# run a for loop to be able to fetch the data in batches
		for batch in range(0,len(original_data),batch_size):
			data = original_data[batch:batch+batch_size] # fetch bacthes
			
			# I am not sure if this should be a numpy array
			# but if it should, please use the appropriate type casting
			# data = np.array(data).astype(np.float32) --> this is an example
			# Find your appropriate casting and set it as such

			# yield this current batch of data
			yield data


"""
H0w to use this in your code
-------------------------------------------------

import tensorflow as tf
from data_generator import data_generator

custom_genenerator = data_generator(parameter_1, optional_param_2)

dataset = tf.data.Dataset.from_generator(custom_genenerator,(tf.float32, tf.int16))
iterator = dataset.make_one_shot_iterator()

x,y = iterator.get_next()



Check the following references for explanation
--------------------------------------------------
Ref: 
https://sknadig.me/TensorFlow2.0-dataset/
https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_generator

"""

Thanks for replying!But I am sorry I have not made progress yet.
Are there any codes about batch size that can be modified to reduce directly?

from c3d-tensorflow.

Related Issues (20)

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.