Skip to content

Show generated ops #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: rn_java_op_gen
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -29,69 +29,61 @@

/**
* Produces a visualization of audio data over time.
* <p>
* Spectrograms are a standard way of representing audio information as a series of
* slices of frequency information, one slice for each window of time. By joining
* these together into a sequence, they form a distinctive fingerprint of the sound
* over time.
* <p>
* This op expects to receive audio data as an input, stored as floats in the range
* <p>This op expects to receive audio data as an input, stored as floats in the range
* -1 to 1, together with a window width in samples, and a stride specifying how
* far to move the window between slices. From this it generates a three
* dimensional output. The first dimension is for the channels in the input, so a
* stereo audio input would have two here for example. The second dimension is time,
* with successive frequency slices. The third dimension has an amplitude value for
* each frequency during that time slice.
* <p>
* This means the layout when converted and saved as an image is rotated 90 degrees
* <p>This means the layout when converted and saved as an image is rotated 90 degrees
* clockwise from a typical spectrogram. Time is descending down the Y axis, and
* the frequency decreases from left to right.
* <p>
* Each value in the result represents the square root of the sum of the real and
* <p>Each value in the result represents the square root of the sum of the real and
* imaginary parts of an FFT on the current window of samples. In this way, the
* lowest dimension represents the power of each frequency in the current window,
* and adjacent windows are concatenated in the next dimension.
* <p>
* To get a more intuitive and visual look at what this operation does, you can run
* <p>To get a more intuitive and visual look at what this operation does, you can run
* tensorflow/examples/wav_to_spectrogram to read in an audio file and save out the
* resulting spectrogram as a PNG image.
*/
@Operator(group = "audio")
@Operator(
group = "audio"
)
public final class AudioSpectrogram extends RawOp implements Operand<TFloat32> {

/**
* Optional attributes for {@link org.tensorflow.op.audio.AudioSpectrogram}
* The name of this op, as known by TensorFlow core engine
*/
public static class Options {

/**
* @param magnitudeSquared Whether to return the squared magnitude or just the
* magnitude. Using squared magnitude can avoid extra calculations.
*/
public Options magnitudeSquared(Boolean magnitudeSquared) {
this.magnitudeSquared = magnitudeSquared;
return this;
}

private Boolean magnitudeSquared;

private Options() {
}
public static final String OP_NAME = "AudioSpectrogram";

private Output<TFloat32> spectrogram;

private AudioSpectrogram(Operation operation) {
super(operation);
int outputIdx = 0;
spectrogram = operation.output(outputIdx++);
}

/**
* Factory method to create a class wrapping a new AudioSpectrogram operation.
*
*
* @param scope current scope
* @param input Float representation of audio data.
* @param windowSize How wide the input window is in samples. For the highest efficiency
* this should be a power of two, but other values are accepted.
* @param stride How widely apart the center of adjacent sample windows should be.
* @param options carries optional attributes values
* @param options carries optional attribute values
* @return a new instance of AudioSpectrogram
*/
@Endpoint(describeByClass = true)
public static AudioSpectrogram create(Scope scope, Operand<TFloat32> input, Long windowSize, Long stride, Options... options) {
@Endpoint(
describeByClass = true
)
public static AudioSpectrogram create(Scope scope, Operand<TFloat32> input, Long windowSize,
Long stride, Options... options) {
OperationBuilder opBuilder = scope.env().opBuilder("AudioSpectrogram", scope.makeOpName("AudioSpectrogram"));
opBuilder.addInput(input.asOutput());
opBuilder = scope.apply(opBuilder);
Expand All @@ -106,35 +98,51 @@ public static AudioSpectrogram create(Scope scope, Operand<TFloat32> input, Long
}
return new AudioSpectrogram(opBuilder.build());
}

/**
* Sets the magnitudeSquared option.
*
* @param magnitudeSquared Whether to return the squared magnitude or just the
* magnitude. Using squared magnitude can avoid extra calculations.
* @return this Options instance.
*/
public static Options magnitudeSquared(Boolean magnitudeSquared) {
return new Options().magnitudeSquared(magnitudeSquared);
}

/**
* Gets spectrogram.
* 3D representation of the audio frequencies as an image.
* @return spectrogram.
*/
public Output<TFloat32> spectrogram() {
return spectrogram;
}

@Override
public Output<TFloat32> asOutput() {
return spectrogram;
}

/** The name of this op, as known by TensorFlow core engine */
public static final String OP_NAME = "AudioSpectrogram";

private Output<TFloat32> spectrogram;

private AudioSpectrogram(Operation operation) {
super(operation);
int outputIdx = 0;
spectrogram = operation.output(outputIdx++);

/**
* Optional attributes for {@link org.tensorflow.op.audio.AudioSpectrogram}
*/
public static class Options {
private Boolean magnitudeSquared;

private Options() {
}

/**
* Sets the magnitudeSquared option.
*
* @param magnitudeSquared Whether to return the squared magnitude or just the
* magnitude. Using squared magnitude can avoid extra calculations.
* @return this Options instance.
*/
public Options magnitudeSquared(Boolean magnitudeSquared) {
this.magnitudeSquared = magnitudeSquared;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,49 @@

/**
* Decode a 16-bit PCM WAV file to a float tensor.
* <p>
* The -32768 to 32767 signed 16-bit values will be scaled to -1.0 to 1.0 in float.
* <p>
* When desired_channels is set, if the input contains fewer channels than this
* <p>When desired_channels is set, if the input contains fewer channels than this
* then the last channel will be duplicated to give the requested number, else if
* the input has more channels than requested then the additional channels will be
* ignored.
* <p>
* If desired_samples is set, then the audio will be cropped or padded with zeroes
* <p>If desired_samples is set, then the audio will be cropped or padded with zeroes
* to the requested length.
* <p>
* The first output contains a Tensor with the content of the audio samples. The
* <p>The first output contains a Tensor with the content of the audio samples. The
* lowest dimension will be the number of channels, and the second will be the
* number of samples. For example, a ten-sample-long stereo WAV file should give an
* output shape of [10, 2].
*/
@Operator(group = "audio")
@Operator(
group = "audio"
)
public final class DecodeWav extends RawOp {

/**
* Optional attributes for {@link org.tensorflow.op.audio.DecodeWav}
* The name of this op, as known by TensorFlow core engine
*/
public static class Options {

/**
* @param desiredChannels Number of sample channels wanted.
*/
public Options desiredChannels(Long desiredChannels) {
this.desiredChannels = desiredChannels;
return this;
}

/**
* @param desiredSamples Length of audio requested.
*/
public Options desiredSamples(Long desiredSamples) {
this.desiredSamples = desiredSamples;
return this;
}

private Long desiredChannels;
private Long desiredSamples;

private Options() {
}
public static final String OP_NAME = "DecodeWav";

private Output<TFloat32> audio;

private Output<TInt32> sampleRate;

private DecodeWav(Operation operation) {
super(operation);
int outputIdx = 0;
audio = operation.output(outputIdx++);
sampleRate = operation.output(outputIdx++);
}

/**
* Factory method to create a class wrapping a new DecodeWav operation.
*
*
* @param scope current scope
* @param contents The WAV-encoded audio, usually from a file.
* @param options carries optional attributes values
* @param options carries optional attribute values
* @return a new instance of DecodeWav
*/
@Endpoint(describeByClass = true)
@Endpoint(
describeByClass = true
)
public static DecodeWav create(Scope scope, Operand<TString> contents, Options... options) {
OperationBuilder opBuilder = scope.env().opBuilder("DecodeWav", scope.makeOpName("DecodeWav"));
opBuilder.addInput(contents.asOutput());
Expand All @@ -103,45 +90,76 @@ public static DecodeWav create(Scope scope, Operand<TString> contents, Options..
}
return new DecodeWav(opBuilder.build());
}

/**
* Sets the desiredChannels option.
*
* @param desiredChannels Number of sample channels wanted.
* @return this Options instance.
*/
public static Options desiredChannels(Long desiredChannels) {
return new Options().desiredChannels(desiredChannels);
}

/**
* Sets the desiredSamples option.
*
* @param desiredSamples Length of audio requested.
* @return this Options instance.
*/
public static Options desiredSamples(Long desiredSamples) {
return new Options().desiredSamples(desiredSamples);
}

/**
* 2-D with shape `[length, channels]`.
* Gets audio.
* 2-D with shape {@code [length, channels]}.
* @return audio.
*/
public Output<TFloat32> audio() {
return audio;
}

/**
* Gets sampleRate.
* Scalar holding the sample rate found in the WAV header.
* @return sampleRate.
*/
public Output<TInt32> sampleRate() {
return sampleRate;
}

/** The name of this op, as known by TensorFlow core engine */
public static final String OP_NAME = "DecodeWav";

private Output<TFloat32> audio;
private Output<TInt32> sampleRate;

private DecodeWav(Operation operation) {
super(operation);
int outputIdx = 0;
audio = operation.output(outputIdx++);
sampleRate = operation.output(outputIdx++);

/**
* Optional attributes for {@link org.tensorflow.op.audio.DecodeWav}
*/
public static class Options {
private Long desiredChannels;

private Long desiredSamples;

private Options() {
}

/**
* Sets the desiredChannels option.
*
* @param desiredChannels Number of sample channels wanted.
* @return this Options instance.
*/
public Options desiredChannels(Long desiredChannels) {
this.desiredChannels = desiredChannels;
return this;
}

/**
* Sets the desiredSamples option.
*
* @param desiredSamples Length of audio requested.
* @return this Options instance.
*/
public Options desiredSamples(Long desiredSamples) {
this.desiredSamples = desiredSamples;
return this;
}
}
}
Loading