Valeria
Valeria

Reputation: 1210

Julia using package located in .julia/dev

I am beginner to Julia though I have experience with Python and some other languages. I get that this is probably a very simple/beginner issue, but I fail to understand how it should work in Julia.

I want to create a Julia module. I saw recommendations to create it with PkgTemplates, so that is exactly what I have done. My directory structure is thus:

enter image description here

It is located at the default path proposed by PkgTemplates: /home/username/.julia/dev/Keras2Flux.

I want to develop it with Revise package due to the slow start-up time of the Julia REPL. However, I fail to import my module to the Julia REPL in the terminal.

So, I cd to the directory mentioned above, use julia command and try using Keras2Flux. I get the error:

ERROR: ArgumentError: Package Keras2Flux not found in current path:

I tried both using Keras2Flux and using Keras2Flux.jl, and I also tried to call it from one level above in my directory structure (i.e. /home/username/.julia/dev). All has the same problem.

What is wrong (more importantly, why?) and how to fix it?

Current contents of the module (not really relevant to the question but still):

module Keras2Flux

import JSON
using Flux

export convert

function create_dense(config)
    in = config["input_dim"]
    out = config["output_dim"]
    dense = Dense(in, outо)
    return dense
end

function create_dropout(config)
    p = config["p"]
    dropout = Dropout(p)
    return dropout
end

function create_model(model_config)
    layers = []
    for layer_config in model_config
        if layer_config["class_name"] == "Dense"
            layer = create_dense(layer_config["config"])
        elseif layer_config["class_name"] == "Dropout"
            layer = create_dropout(layer_config["config"])
        else
            println(layer_config["class_name"])
            throw("unimplemented")
        end
        push!(layers, layer)
    end
    model = Chain(layers)
end

function convert(filename)
    jsontxt = ""
    open(filename, "r") do f
        jsontxt = read(f, String)  
    end
    model_params = JSON.parse(jsontxt)  
    if model_params["keras_version"] == "1.1.0"
        create_model(model_params["config"])
    else
        throw("unimplemented")
    end
end

end

Upvotes: 2

Views: 378

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42214

Here is a full recipe to get you going:

cd("/home/username/.julia/dev")
using Pkg
pkg"generate Keras2Flux"
cd("Keras2Flux")
pkg"activate ."
pkg"add JSON Flux"
# now copy-paste whatever you need to Keras2Flux\src\Keras2Flux.jl
using Revise
using Keras2Flux
# happy development!

Upvotes: 4

Related Questions