Skip to main content

Posts

Showing posts from October, 2022

How to use TFRecord format?

When dealing with the TFRecord format throughout TensorFlow's API, several objects (classes) come out. However, there are surprisingly many, so it seems that it is difficult to understand. Now let's show the objects hierarchically. tf.Example tf.train.Features tf.train.Feature tf.train.BytesList tf.train.FloatList tf.train.Int64List Fundamentally, a tf.train.Example is a {"string": tf.train.Feature} mapping. The tf.train.Feature message type can accept one of the three types( tf.train.BytesList , tf.train.FloatList , and tf.train.Int64List ). Each function takes a scalar input value and returns a tf.train.Feature containing one of the three list types. See https://www.tensorflow.org/tutorials/load_data/tfrecord#creating_a_tftrainexample_message import tensorflow as tf int64_list = tf.train.Int64List(value=[1, 2, 3, 4]) # Or dict can be taken. # int64_list = dict(value=[1, 2, 3, 4]) int64_feature = tf.trai...

Public, Protected, and Private variables in Python

Object-oriented languages, such as C++ and Java, control the access to class resources by public, private, and protected keywords. Python can also introduce a concept of public, protected, and private. But all the variables in Python are public. Private variables of the class are denied access from the environment outside the class, while public variables are accessible from outside the class. Protected variables of a class are accessible from within the class and are also available to its sub-classes. No other environment is permitted access to it. This enables specific resources of the parent class to be inherited by the child class. Declaration methods of valiables Public variables Public variables (generally methods declared in a class) are accessible from outside the class. All the variables in a Python class are public by default. Any variables can be accessed from outside the class environment. Protected variables Python's convention to make an instance variabl...

Iterator object in Python

Python iterable object The 'list' object is one of iterable objects. This makes it possible to consume its elements using a for loop. fruits = ['apple', 'orange', 'grape', 'peach'] print(type(fruits)) for elm in fruits: print(elm) # class 'list' # apple # orange # grape # peach Explicitly create a Python iterator using iter, which is a Built-in Function in Python. iter(object[, sentinel]) Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, object must be a collection object which supports the iterable protocol (the __iter__() method), or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0). If it does not support either of those protocols, TypeError is raised. If the second argument, sentinel, is given, then object must be a callable object. The iterator created in this ...