module - Julia 使用位于 .julia/dev 中的包

标签 module julia

尽管我有 Python 和其他一些语言的经验,但我还是 Julia 的初学者。我知道这可能是一个非常简单/初学者的问题,但我无法理解它在 Julia 中应该如何工作。

我想创建一个 Julia 模块。我看到了使用 PkgTemplates 创建它的建议,所以这正是我所做的。我的目录结构是这样的:

enter image description here

它位于PkgTemplates建议的默认路径:/home/username/.julia/dev/Keras2Flux

由于 Julia REPL 的启动时间很慢,我想使用 Revise 包来开发它。但是,我无法将模块导入终端中的 Julia REPL。

因此,我 cd 到上述目录,使用 julia 命令并尝试使用 Keras2Flux。我收到错误:

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

我尝试了使用 Keras2Flux使用 Keras2Flux.jl,并且我还尝试从我的目录结构中的上一层(即 /home/用户名/.julia/dev)。大家都有同样的问题。

出了什么问题(更重要的是,为什么?)以及如何修复它?

模块的当前内容(与问题并不真正相关,但仍然如此):

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

最佳答案

这里有一个完整的食谱可以帮助您:

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!

关于module - Julia 使用位于 .julia/dev 中的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62427351/

相关文章:

haskell - 在 Haskell 中导入数据类型

c - 如何从另一个模块调用导出的内核模块函数?

C# Process.GetProcessById(4) 抛出 System.ComponentModel.Win32Exception

julia - 如何在 Julia 中扩展 Base.∘ 方法

Julia:尝试添加 slider 时出现 "Plot not defined"

node.js - 导出变量 'router' 具有或正在使用来自外部模块的名称 'Router' 但无法命名

module - 在 SWI-Prolog 中,meta_predicate 的数字参数意味着什么?

arrays - 如何在 Julia 中按行压缩 2D 和 1D 数组?

integer - Julia 中 2 个正数的乘积得到负数

julia - Julia 有函数装饰器吗?