Struct tfrecord::event_writer::EventWriter
source · [−]pub struct EventWriter<W> { /* private fields */ }
Expand description
The event writer.
It provies write_scalar
, write_image
methods, etc.
It can be built from a writer using from_writer, or write a new file specified by path prefix using from_writer.
use anyhow::Result;
use std::time::SystemTime;
use tch::{kind::FLOAT_CPU, Tensor};
use tfrecord::EventWriter;
let mut writer = EventWriter::from_prefix("log_dir/myprefix-", "", Default::default()).unwrap();
// step = 0, scalar = 3.14
writer.write_scalar("my_scalar", 0, 3.14)?;
// step = 1, specified wall time, histogram of [1, 2, 3, 4]
writer.write_histogram("my_histogram", (1, SystemTime::now()), vec![1, 2, 3, 4])?;
// step = 2, specified raw UNIX time in nanoseconds, random tensor of shape [8, 3, 16, 16]
writer.write_tensor(
"my_tensor",
(2, 1.594449514712264e+18),
Tensor::randn(&[8, 3, 16, 16], FLOAT_CPU),
)?;
Implementations
sourceimpl EventWriter<BufWriter<File>>
impl EventWriter<BufWriter<File>>
sourcepub fn create<P>(path: P, config: EventWriterConfig) -> Result<Self> where
P: AsRef<Path>,
pub fn create<P>(path: P, config: EventWriterConfig) -> Result<Self> where
P: AsRef<Path>,
Build a writer writing events to a file.
sourcepub fn from_prefix<'a, 'b, P, S>(
prefix: P,
file_name_suffix: S,
config: EventWriterConfig
) -> Result<EventWriter<BufWriter<File>>> where
P: Into<Cow<'a, str>>,
S: Into<Cow<'b, str>>,
pub fn from_prefix<'a, 'b, P, S>(
prefix: P,
file_name_suffix: S,
config: EventWriterConfig
) -> Result<EventWriter<BufWriter<File>>> where
P: Into<Cow<'a, str>>,
S: Into<Cow<'b, str>>,
Build a writer writing events to a file, which path is specified by a path prefix and file name suffix.
sourceimpl<W> EventWriter<W> where
W: Write,
impl<W> EventWriter<W> where
W: Write,
sourcepub fn from_writer(writer: W, config: EventWriterConfig) -> Result<Self> where
W: Write,
pub fn from_writer(writer: W, config: EventWriterConfig) -> Result<Self> where
W: Write,
Build from a writer with Write trait.
sourcepub fn write_scalar(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
value: f32
) -> Result<()>
pub fn write_scalar(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
value: f32
) -> Result<()>
Write a scalar summary.
sourcepub fn write_histogram(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
histogram: impl IntoHistogram
) -> Result<()>
pub fn write_histogram(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
histogram: impl IntoHistogram
) -> Result<()>
Write a histogram summary.
sourcepub fn write_tensor(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
tensor: impl TryInto<TensorProto, Error = impl Into<Error>>
) -> Result<()>
pub fn write_tensor(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
tensor: impl TryInto<TensorProto, Error = impl Into<Error>>
) -> Result<()>
Write a tensor summary.
sourcepub fn write_image(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
image: impl TryInto<Image, Error = impl Into<Error>>
) -> Result<()>
pub fn write_image(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
image: impl TryInto<Image, Error = impl Into<Error>>
) -> Result<()>
Write an image summary.
sourcepub fn write_image_list(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
images: impl IntoImageList
) -> Result<()>
pub fn write_image_list(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
images: impl IntoImageList
) -> Result<()>
Write a summary with multiple images.
sourcepub fn write_audio(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
audio: impl TryInto<Audio, Error = impl Into<Error>>
) -> Result<()>
pub fn write_audio(
&mut self,
tag: impl ToString,
event_meta: impl Into<EventMeta>,
audio: impl TryInto<Audio, Error = impl Into<Error>>
) -> Result<()>
Write an audio summary.
sourcepub fn write_event(&mut self, event: Event) -> Result<()>
pub fn write_event(&mut self, event: Event) -> Result<()>
Write a custom event.
Trait Implementations
sourceimpl<W: Clone> Clone for EventWriter<W>
impl<W: Clone> Clone for EventWriter<W>
sourcefn clone(&self) -> EventWriter<W>
fn clone(&self) -> EventWriter<W>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<W: Debug> Debug for EventWriter<W>
impl<W: Debug> Debug for EventWriter<W>
sourceimpl<W: PartialEq> PartialEq<EventWriter<W>> for EventWriter<W>
impl<W: PartialEq> PartialEq<EventWriter<W>> for EventWriter<W>
sourcefn eq(&self, other: &EventWriter<W>) -> bool
fn eq(&self, other: &EventWriter<W>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &EventWriter<W>) -> bool
fn ne(&self, other: &EventWriter<W>) -> bool
This method tests for !=
.
impl<W> StructuralPartialEq for EventWriter<W>
Auto Trait Implementations
impl<W> RefUnwindSafe for EventWriter<W> where
W: RefUnwindSafe,
impl<W> Send for EventWriter<W> where
W: Send,
impl<W> Sync for EventWriter<W> where
W: Sync,
impl<W> Unpin for EventWriter<W> where
W: Unpin,
impl<W> UnwindSafe for EventWriter<W> where
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more