CometLogger.jl

Log data to comet.ml from Julia

CometLogger is a Julia package that allows you to log data to Comet through the standard Julia Logging system.

Installation

To install this Julia package run the following command in the julia REPL:

] add CometLogger

Basic Usage

The main type in the package is CLogger. It behaves like any other standard logger in Julia like ConsoleLogger.

Note

Make sure you obtain your API key from Comet and store it at $HOME/.comet.config as:

[comet]
api_key = YOUR_API_KEY

You can pass in the same arguments to CLogger as specied for comet_ml.Experiment in their Python API.

Once you have created a CLogger, you can use it as you would use any other logger in Julia:

  • You can set it to be your global logger with the function global_logger
  • You can set it to be the current logger in a scope with the function with_logger
  • You can combine it with other Loggers using LoggingExtras.jl, so that messages are logged to TensorBoard and to other backends at the same time.

Every CLogger has an internal counter to store the current step, which is initially set to 1. All the data logged with the same @log call will be logged with the same step, and then it will increment the internal counter by 1.

If you want to increase the counter by a different amount, or prevent it from increasing, you can log the additional message log_step_increment=N. The default behaviour corresponds to N=1. If you set N=0 the internal counter will not be modified.

See the example below:

using TensorBoardLogger, Logging, Random

lg=CLogger(min_level=Logging.Info)

struct sample_struct first_field; other_field; end

with_logger(lg) do
    for i=1:100
        data_struct = sample_struct(i^2, i^1.5-0.3*i)


        @info "test" i=i j=i^2 dd=rand(10).+0.1*i 
        @info "test_2" i=i j=2^i log_step_increment=0
        @info "" my_weird_struct=data_struct   log_step_increment=0
        @debug "debug_msg" this_wont_show_up=i
    end
end

Third-party packages

We also support logging custom types from a the following third-party libraries:

  • Plots.jl: the Plots.Plot type will be rendered to PNG at the resolution specified by the object and logged as an image
Note

Make sure to load Plots and ImageIO if you wish to log Plots.jl plots.

Explicit Interface

In addition to the standard logging interface, it is possible to log data to Comet using the functions documented below. All the functions accept take as first argument a CLogger object and as the second argument a String as the tag under which the data will be logged.

Scalar

CometLogger.log_metricFunction
function log_metric(lg::CLogger, name::AbstractString, value::Real; step::Int=nothing, epoch::Int=nothing)

Logs general scalar metrics.

source

Text

CometLogger.log_textFunction
function log_text(lg::CLogger, name::AbstractString, value::AbstractString; step::Int=nothing, metadata::Dict{String,Any}=nothing)

Logs the text.

source

Images

CometLogger.log_imageFunction
function log_image(lg::CLogger, name::AbstractString, obj::AbstractString; step=nothing, kwargs...)

Logs the image from a filepath.

source

Index

CometLogger.log_imageMethod
function log_image(lg::CLogger, name::AbstractString, obj::AbstractString; step=nothing, kwargs...)

Logs the image from a filepath.

source
CometLogger.log_metricMethod
function log_metric(lg::CLogger, name::AbstractString, value::Real; step::Int=nothing, epoch::Int=nothing)

Logs general scalar metrics.

source
CometLogger.log_textMethod
function log_text(lg::CLogger, name::AbstractString, value::AbstractString; step::Int=nothing, metadata::Dict{String,Any}=nothing)

Logs the text.

source
CometLogger.logable_propertynamesMethod
logable_propertynames(val::Any)

Returns a tuple with the name of the fields of the structure val that should be logged to Comet.ml. This function should be overridden when you want Comet.ml to ignore some fields in a structure when logging it. The default behaviour is to return the same result as propertynames. See also: Base.propertynames

source