A minimal example for creating, compiling and using a static library in C++.
// test.h
#pragma once
int add(int a, int b);
int mult(int a, int b);| class CosineDecayWithWarmup(tf.keras.optimizers.schedules.LearningRateSchedule): | |
| def __init__( | |
| self, | |
| warmup_steps, | |
| total_steps, | |
| base_lr=0.001, | |
| ): | |
| super(CosineDecayWithWarmup, self).__init__() | |
| self.warmup_steps = warmup_steps |
| import tensorflow as tf | |
| # Reset states (to be sure) | |
| tf.keras.backend.clear_session() | |
| # Method 1 | |
| x = tf.keras.Input(shape=(224, 224, 3), dtype=tf.uint8) | |
| c = tf.keras.layers.Flatten()(x) | |
| y = tf.keras.layers.Dense(units=2, activation="softmax")(c) | |
| model1 = tf.keras.Model(inputs=x, outputs=y) |
| function image_pad_or_crop(image, output_height, output_width) { | |
| // Pads or crops an image so that the height and width dimensions match output_height and output_width. | |
| // This function is compatible with tf.image.resize_with_crop_or_pad(image, target_height, target_width) | |
| // Validate inputs | |
| const image_size = image.height * image.width * image.depth; | |
| if (image.data.length != image_size) { | |
| console.log("Error: image dimensions do not match rgba buffer size!"); | |
| return null; | |
| } |
| function zeropad(image, top, bottom, left, right) { | |
| // Pads an image with a specified amount of zeros on the top, left, bottom and right. | |
| // Validate inputs | |
| const image_size = image.height * image.width * image.depth; | |
| if (image.data.length != image_size) { | |
| console.log("Error: image dimensions do not match rgba buffer size!"); | |
| return null; | |
| } | |
| if (image.data.constructor !== Uint8ClampedArray && image.data.constructor !== Float32Array) { |
| function distribute_recordings_over_lines(num_recordings, distribution, lines) { | |
| // This function distributes number of recordings optimally | |
| // given the current distribution and the lines on which you want to record. | |
| function find_level(n, distribution, lines, low, high) { | |
| // Compute the level | |
| const level = (low + high) / 2; | |
| // Compute search statistic | |
| let s = 0; |
| function resizeBicubic(image, newHeight, newWidth) { | |
| /* Helper functions */ | |
| function extrapolateImageBoundaries(image) { | |
| const height = image.length; | |
| const width = image[0].length; | |
| // Linearly extrapolate top and bottom of the image | |
| image[-2] = []; |
| function demosaic(raw) { | |
| // Demosaics a Color Filter Array (CFA) into a RGBA color array. | |
| // For implementation details see: http://research.microsoft.com/pubs/102068/demosaicing_icassp04.pdf | |
| // Validate inputs | |
| const raw_size = raw.height * raw.width * raw.depth; | |
| if (raw.data.length != raw_size) { | |
| console.log("Error: raw image dimensions do not match raw buffer size!"); | |
| return null; | |
| } |
| <html> | |
| <body> | |
| <canvas id="mycanvas" width="2048" height="512"></canvas> | |
| </body> | |
| </html> | |
| <script> | |
| const height = 512; |