# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil var = tf.Variable("1", dtype=tf.string) tfutil.print_variable(var) print(var) num1 = tf.string_to_number(var, out_type=tf.int32) tfutil.print_operation_value(num1) print(num1) const = tf.constant("2", dtype=tf.string) tfutil.print_constant(const) print(const) num2 = tf.string_to_number(const, out_type=tf.float32) tfutil.print_operation_value(num2) print(num2)
tfutil.print_constant(const1) # Ksizes Test # output_depth = ksize_rows * ksize_cols * depth = (1 x 1 x 1 ) = 1 # ksizes: raws: [1] col: [1] ksizes = [1, 1, 1, 1] strides = [1, 3, 3, 1] rates = [1, 1, 1, 1] exi_const1 = tf.extract_image_patches(const1, ksizes, strides, rates, padding='VALID') print(exi_const1) print(tf.shape(exi_const1)) tfutil.print_operation_value(exi_const1) # Ksizes Test # output_depth = ksize_rows * ksize_cols * depth = (1 x 2 x 1 ) = 2 # ksizes: raws: [1, 2] col: [1, 2] ksizes = [1, 1, 2, 1] strides = [1, 3, 3, 1] rates = [1, 1, 1, 1] exi_const1 = tf.extract_image_patches(const1, ksizes, strides, rates, padding='VALID') print(exi_const1) print(tf.shape(exi_const1)) tfutil.print_operation_value(exi_const1)
#!/usr/bin/python import tensorflow as tf import numpy as np import tfutil # [1, 2, 3, 4, 5, 6, 7, 8, 9] const1 = tf.constant(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) sp1_const1, sp2_const1 = tf.split(const1, 2, 0) print(sp1_const1) print(tf.shape(sp1_const1)) tfutil.print_operation_value(sp1_const1) print(sp2_const1) print(tf.shape(sp2_const1)) tfutil.print_operation_value(sp2_const1) # [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]], [[13, 14, 15], [16, 17, 18]]] const2 = tf.constant([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], [17, 18, 19, 20]]) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2) sp1_const2, sp2_const2 = tf.split(const2, 2, 1) print(sp1_const2) print(tf.shape(sp1_const2))
const1 = tf.constant(np.array(x), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) # return: [batch*block_size*block_size, height_pad/block_size, width_pad/block_size, depth] # paddings = [[pad_top, pad_bottom], [pad_left, pad_right]] # height_pad = pad_top + height + pad_bottom # width_pad = pad_left + width + pad_right # blocksize = Both height_pad and width_pad must be divisible by block_size. paddings = [[0, 0], [0, 0]] blocksize = 1 stb_const1 = tf.space_to_batch(const1, paddings, blocksize) print(stb_const1) print(tf.shape(stb_const1)) tfutil.print_operation_value(stb_const1) paddings = [[0, 0], [0, 1]] blocksize = 1 stb_const1 = tf.space_to_batch(const1, paddings, blocksize) print(stb_const1) print(tf.shape(stb_const1)) tfutil.print_operation_value(stb_const1) paddings = [[0, 0], [1, 1]] blocksize = 1 stb_const1 = tf.space_to_batch(const1, paddings, blocksize) print(stb_const1) print(tf.shape(stb_const1)) tfutil.print_operation_value(stb_const1)
tfutil.print_constant(const1) const2 = tf.constant(np.array([4, 5, 6]), dtype=tf.int32) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2) const3 = tf.constant(np.array([7, 8, 9]), dtype=tf.int32) print(const3) print(tf.shape(const3)) tfutil.print_constant(const3) pack_const1 = tf.stack([const1, const2, const3]) print(pack_const1) print(tf.shape(pack_const1)) tfutil.print_operation_value(pack_const1) up_const1, up_const2, up_const3 = tf.unstack(pack_const1) print(up_const1) print(tf.shape(up_const1)) tfutil.print_constant(up_const1) print(up_const2) print(tf.shape(up_const2)) tfutil.print_constant(up_const2) print(up_const3) print(tf.shape(up_const3)) tfutil.print_constant(up_const3) pack_const1 = tf.stack([const1, const2, const3], axis=1)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant(1) tfutil.print_constant(const1) print(const1) float1 = tf.to_float(const1) tfutil.print_operation_value(float1) print(float1) const2 = tf.constant([2, 3]) tfutil.print_constant(const2) print(const2) float2 = tf.to_float(const2) tfutil.print_operation_value(float2) print(float2) var1 = tf.Variable(4) tfutil.print_variable(var1) print(var1) float3 = tf.to_float(var1) tfutil.print_operation_value(float3) print(float3) var2 = tf.Variable([5, 6]) tfutil.print_variable(var2) print(var2) float4 = tf.to_float(var2)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant(1, dtype=tf.float32) tfutil.print_constant(const1) print(const1) int32_1 = tf.to_int32(const1) tfutil.print_operation_value(int32_1) print(int32_1) const2 = tf.constant([2, 3], dtype=tf.float32) tfutil.print_constant(const2) print(const2) int32_2 = tf.to_int32(const2) tfutil.print_operation_value(int32_2) print(int32_2) var1 = tf.Variable(4, dtype=tf.float32) tfutil.print_variable(var1) print(var1) int32_3 = tf.to_int32(var1) tfutil.print_operation_value(int32_3) print(int32_3) var2 = tf.Variable([5, 6], dtype=tf.float32) tfutil.print_variable(var2) print(var2) int32_4 = tf.to_int32(var2)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant(127, dtype=tf.int32) tfutil.print_constant(const1) print(const1) f32 = tf.cast(const1, tf.float32) tfutil.print_operation_value(f32) print(f32) f64 = tf.cast(const1, tf.float64) tfutil.print_operation_value(f64) print(f64) i8 = tf.cast(const1, tf.int8) tfutil.print_operation_value(i8) print(i8) i16 = tf.cast(const1, tf.int16) tfutil.print_operation_value(i16) print(i16) i64 = tf.cast(const1, tf.int64) tfutil.print_operation_value(i64) print(i64) u8 = tf.cast(const1, tf.uint8) tfutil.print_operation_value(u8) print(u8) ''' # not support s = tf.cast(const1, tf.string) tfutil.print_operation_value(s)
# outputs[i].shape = [sum(partitions == i)] + data.shape[partitions.ndim:] # outputs[i] = pack([data[js, ...] for js if partitions[js] == i]) x = [10, 20] const1 = tf.constant(np.array(x)) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) # Scalar partitions. partitions = 1 num_partitions = 2 dyp_const1 = tf.dynamic_partition(const1, partitions, num_partitions) print(dyp_const1[0]) print(tf.shape(dyp_const1[0])) tfutil.print_operation_value(dyp_const1[0]) print(dyp_const1[1]) print(tf.shape(dyp_const1[1])) tfutil.print_operation_value(dyp_const1[1]) print(dyp_const1) print(tf.shape(dyp_const1)) tfutil.print_operation_value(dyp_const1) x = [10, 20, 30, 40, 50] const2 = tf.constant(np.array(x)) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2)
import tensorflow as tf import numpy as np import tfutil x = [[[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]] const1 = tf.constant(np.array(x), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) dims = [3] dims_const1 = tf.reverse(const1, dims) print(dims_const1) print(tf.shape(dims_const1)) tfutil.print_operation_value(dims_const1) dims = [1] dims_const1 = tf.reverse(const1, dims) print(dims_const1) print(tf.shape(dims_const1)) tfutil.print_operation_value(dims_const1) dims = [2] dims_const1 = tf.reverse(const1, dims) print(dims_const1) print(tf.shape(dims_const1)) tfutil.print_operation_value(dims_const1)
# Vector indices: merged[indices[m][i], ...] = data[m][i, ...] merged.shape = [max(indices)] + constant ''' x = [[1, 2], [3, 4]] const1 = tf.constant(np.array(x)) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) indice = [[0, 1], [2, 3]] dys_const1 = tf.dynamic_stitch(indice, const1) print(dys_const1[0]) print(tf.shape(dys_const1[0])) tfutil.print_operation_value(dys_const1[0]) x = [[1, 2], [3, 4]] const1 = tf.constant(np.array(x)) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) y = [1, 1] row_to_add = tf.constant(np.array(y)) print(row_to_add) print(tf.shape(row_to_add)) tfutil.print_constant(row_to_add) original_row = const1[0] print(original_row)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant([1, 2, 3, 4, 5, 6, 7, 8, 9]) print(const1) tfutil.print_constant(const1) rs_const1 = tf.reshape(const1, [3, 3]) print(rs_const1) tfutil.print_operation_value(rs_const1) const2 = tf.constant([[[1, 1], [2, 2]], [[3, 3], [4, 4]]]) print(const2) tfutil.print_constant(const2) rs_const2 = tf.reshape(const2, [2, 4]) print(rs_const2) tfutil.print_operation_value(rs_const2) const3 = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], [[5, 5, 5], [6, 6, 6]]]) print(const3) tfutil.print_constant(const3) rs_const3 = tf.reshape(const3, [-1]) print(rs_const3) tfutil.print_operation_value(rs_const3) const4 = tf.constant([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]) print(const4) tfutil.print_constant(const4)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant(1) tfutil.print_constant(const1) print(const1) tfutil.print_operation_value(tf.shape(const1)) const2 = tf.constant([1, 2]) tfutil.print_constant(const2) print(const2) tfutil.print_operation_value(tf.shape(const2)) const3 = tf.constant([[1, 2], [3, 4]]) tfutil.print_constant(const3) print(const3) tfutil.print_operation_value(tf.shape(const3)) const4 = tf.constant([[1, 2], [3, 4], [5, 6]]) tfutil.print_constant(const4) print(const4) tfutil.print_operation_value(tf.shape(const4)) const5 = tf.constant([[[1], [2]], [[3], [4]]]) tfutil.print_constant(const5) print(const5) tfutil.print_operation_value(tf.shape(const5))
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1, const2 = tf.constant([1]), tf.constant([2, 3]) var1, var2 = tf.Variable([4]), tf.Variable([5, 6]) tfutil.print_constant(const1) tfutil.print_constant(const2) tfutil.print_variable(var1) tfutil.print_variable(var2) print('add operation section') tfutil.print_operation_value(tf.add(const1, var1)) tfutil.print_operation_value(tf.add(const2, var2)) print('subtract operation section') tfutil.print_operation_value(tf.subtract(const1, var1)) tfutil.print_operation_value(tf.subtract(const2, var2)) print('multiply operation section') tfutil.print_operation_value(tf.multiply(const1, var1)) tfutil.print_operation_value(tf.multiply(const2, var2)) print('div operation section') tfutil.print_operation_value(tf.div(const1, var1)) tfutil.print_operation_value(tf.div(const2, var2)) print('mod operation section')
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import numpy as np import tfutil x = 37.0 const1 = tf.constant(x) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) bc_const1 = tf.bitcast(const1, tf.int32) print(bc_const1) print(tf.shape(bc_const1)) tfutil.print_operation_value(bc_const1) x = -1 invert_bits = tf.constant(x) - bc_const1 print(invert_bits) print(tf.shape(invert_bits)) tfutil.print_operation_value(invert_bits) bc_to_float = tf.bitcast(invert_bits, tf.float32) print(bc_to_float) print(tf.shape(bc_to_float)) tfutil.print_operation_value(bc_to_float)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import numpy as np import tfutil x = [0, 1, 2, 3] const1 = tf.constant(np.array(x)) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) mask = np.array([True, False, True, False]) bm_const1 = tf.boolean_mask(const1, mask) print(bm_const1) print(tf.shape(bm_const1)) tfutil.print_operation_value(bm_const1) x = [[1, 2], [3, 4], [5, 6]] const2 = tf.constant(np.array(x)) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2) mask = np.array([True, False, True]) bm_const2 = tf.boolean_mask(const2, mask) print(bm_const2) print(tf.shape(bm_const2)) tfutil.print_operation_value(bm_const2)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import tfutil const1 = tf.constant(1) tfutil.print_constant(const1) print(const1) double1 = tf.to_double(const1) tfutil.print_operation_value(double1) print(double1) const2 = tf.constant([2, 3]) tfutil.print_constant(const2) print(const2) double2 = tf.to_double(const2) tfutil.print_operation_value(double2) print(double2) var1 = tf.Variable(4) tfutil.print_variable(var1) print(var1) double3 = tf.to_double(var1) tfutil.print_operation_value(double3) print(double3) var2 = tf.Variable([5, 6]) tfutil.print_variable(var2) print(var2) double4 = tf.to_double(var2)
# -*- coding: utf-8 -*- #!/usr/bin/python import tensorflow as tf import numpy as np import tfutil # [[1, 2, 3], [4, 5, 6]] # [[7, 8, 9], [10, 11, 12]] const1 = tf.constant(np.array([[1, 2, 3], [4, 5, 6]]), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) const2 = tf.constant(np.array([[7, 8, 9], [10, 11, 12]]), dtype=tf.int32) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2) cc_const1 = tf.concat([const1, const2], 0) print(cc_const1) print(tf.shape(cc_const1)) tfutil.print_operation_value(cc_const1) cc_const1 = tf.concat([const1, const2], 1) print(cc_const1) print(tf.shape(cc_const1)) tfutil.print_operation_value(cc_const1)
import tensorflow as tf import numpy as np import tfutil x = [[[[1, 2, 3, 4]]]] const1 = tf.constant(np.array(x), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) blocksize = 2 dts_const1 = tf.depth_to_space(const1, blocksize) print(dts_const1) print(tf.shape(dts_const1)) tfutil.print_operation_value(dts_const1) x = [[[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]]] const2 = tf.constant(np.array(x), dtype=tf.int32) print(const2) print(tf.shape(const2)) tfutil.print_constant(const2) blocksize = 2 dts_const2 = tf.depth_to_space(const2, blocksize) print(dts_const2) print(tf.shape(dts_const2)) tfutil.print_operation_value(dts_const2) x = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]] const3 = tf.constant(np.array(x), dtype=tf.int32)
const1 = tf.constant(np.array(x), dtype=tf.int32) print(const1) print(tf.shape(const1)) tfutil.print_constant(const1) # crops = [[crop_top, crop_bottom], [crop_left, crop_right]] # [batch, height, width, depth] # height = height_pad - crop_top - crop_bottom # width = width_pad - crop_left - crop_right corps = [[0, 0],[0, 1]] blocksize = 1 bts_const1 = tf.batch_to_space(const1, corps, blocksize) print(bts_const1) print(tf.shape(bts_const1)) tfutil.print_operation_value(bts_const1) corps = [[0, 0],[0, 1]] blocksize = 1 bts_const1 = tf.batch_to_space(const1, corps, blocksize) print(bts_const1) print(tf.shape(bts_const1)) tfutil.print_operation_value(bts_const1) corps = [[0, 1],[0, 0]] blocksize = 1 bts_const1 = tf.batch_to_space(const1, corps, blocksize) print(bts_const1) print(tf.shape(bts_const1)) tfutil.print_operation_value(bts_const1)