0

I ran the TensorFlow profiler using Python and got several types and operations.

Is there a way to change the name of the type and make it output with the changed name when profiling is performed? For example, I would like to know if there is a way to rename a type named Conv2D to conv2D_LOVE so that it is output to the profiler.

I'm currently searching, but I can't find the right way.

For example, I use the Alexnet model, and after profiling I got this output:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yy hh
  • 11
  • 1

1 Answers1

-1

There are many of the class inherits that are allowed for the customizations. One is the Dense and LSTM layer. They are suitable to perform tasks internally and return you specific data as blocks of code.

Sample:

import tensorflow as tf
import matplotlib.pyplot as plt

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Class / Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
class My_3D_noises_generator(tf.keras.layers.Layer):
    def __init__(self, num_outputs):
        super(My_3D_noises_generator, self).__init__()
        self.num_outputs = num_outputs

    def build(self, input_shape):
        self.kernel = self.add_weight("kernel",
        shape=[int(input_shape[-1]),
        self.num_outputs],
        initializer=tf.ones_initializer())

    def call(self, inputs):

        pi = 3.141592653589793
        start = 0.0
        stop = 1.0 * 2.0 * pi

        x = tf.linspace( start, stop, self.num_outputs, name='linspace', axis=0 )
        y1 = 3 * tf.math.sin( x )

        escape_sine = tf.random.normal(
            shape=( self.num_outputs, ),
            mean=0.0,
            stddev=0.15 * tf.math.abs( y1, name='abs' ),
            dtype=tf.dtypes.float32,
            seed=32,
            name=None
        )

        y1 = tf.concat( (tf.zeros(60), y1 + escape_sine, tf.zeros(60)), axis=0, name='concat' )
        initial_degree = tf.experimental.numpy.arange( -3, 0, 3 / 60, dtype=tf.float32 )
        midring_degree = tf.experimental.numpy.arange( 0, 3 * 2 * pi, ( 3 * 2 * pi) / self.num_outputs, dtype=tf.float32 )
        skipped_degree = tf.experimental.numpy.arange( 3 * 2 * pi, 3 * 2 * pi + 3, ( 3 * 2 * pi - 3 * 2 * pi + 3 ) / 60, dtype=tf.float32 )

        x = tf.concat(( initial_degree.numpy(), midring_degree.numpy(), skipped_degree.numpy()), axis=0, name='concat')
        y2 = 0.1 * x + 1
        y = y1 + y2
        z = 15 * tf.random.normal(
            shape=( 1, self.num_outputs, ),
            mean=0.0,
            stddev=1,
            dtype=tf.dtypes.float32,
            seed=32,
            name=None
        )

        x = tf.expand_dims(x, axis=0)
        y = tf.expand_dims(y, axis=0)

        z = tf.matmul(inputs, z)
        x = tf.matmul(inputs, x)
        y = tf.matmul(inputs, y)

        x = x[int(tf.math.argmax(x, axis=0)[0])]
        y = y[int(tf.math.argmax(y, axis=0)[0])]
        z = z[int(tf.math.argmax(z, axis=0)[0])]

        x = tf.expand_dims(x, axis=-1)
        y = tf.expand_dims(y, axis=-1)
        z = tf.expand_dims(z, axis=-1)

        return x, y, z

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Perform operations
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
start = 3
limit = 33
delta = 3
sample = tf.range(start, limit, delta)
sample = tf.cast( sample, dtype=tf.float32 )
sample = tf.constant( sample, shape=( 10, 1 ) )
layer = My_3D_noises_generator(100)
xdata, ydata, zdata = layer(sample)

ax = plt.axes(projection='3d')
# Data for a three-dimensional line
zline = tf.range(0, 1000, 25)
zline = tf.cast( zline, dtype=tf.float32 )
xline = 20 * tf.math.sin(zline)
yline = 20 * tf.math.cos(zline)
ax.plot3D(xline, yline, zline, 'gray')
ax.scatter3D(xdata[0:100,:], ydata[0:100,:], zdata[0:100,:], c=zdata[0:100,:], cmap='Greens');

plt.show()

Output: Generated random noises in 3D try to catches them.

Sample

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    Your code does not make sense in the context of your answer, which is wrong anyway. If it's not wrong, it's not understandable. – General Grievance Dec 06 '22 at 16:13
  • The question is how to change the layer name, I show him it is just a class or block code he can name anything and create the function inside the block code with supports codes. – Jirayu Kaewprateep Dec 07 '22 at 01:11
  • 1
    Where in your answer did you show that? The author asked specifically about Conv2D. A good answer would have shown how to rename Conv2D instead of posting unwanted code. – General Grievance Dec 07 '22 at 02:10
  • I answer to the question he want to renamed a layer any layer he example is CONV2 and you can see from my codes he can it anything and the result is reflects to internal functions. – Jirayu Kaewprateep Dec 08 '22 at 03:56