1

我正在和 julia 一起学习深度学习,并编写了这些代码。

using LinearAlgebra
using Plots
using Flux.Data
using PyCall
@pyimport pickle
@pyimport numpy as np
using ScikitLearn
@sk_import datasets: fetch_openml
println("import fin")

我得到了这些输出。

┌ Warning: `@pyimport foo` is deprecated in favor of `foo = pyimport("foo")`.
│   caller = _pywrap_pyimport(::PyObject) at PyCall.jl:399
└ @ PyCall C:\Users\Username\.julia\packages\PyCall\zqDXB\src\PyCall.jl:399
import fin

但是在我完成标志后它会消耗更多时间。我在下一个脚本中运行了一些没什么特别的代码。

function AND(x1,x2)
    x = [x1 x2]
    w = [0.5 0.5]       # w1 = w2 ≤ theta
    b = -0.6
    tmp = dot(x,w) + b
    if tmp <= 0
        return 0
    elseif tmp > 0             # 0.5를 넘으면 1, 못넘으면 0 반환
        return 1
    end
end

不仅是代码,markdown 文档在导入后也需要时间运行。是什么导致了这个问题?

4

1 回答 1

1

你的问题有两个问题:

  1. 您应该将 python 模块导入为:

    using PyCall
    pickle = pyimport("pickle")
    np = pyimport("numpy")
    
  2. 在 Julia 中导入模块后,它正在被预编译,因此需要时间。如果您想避免预编译,您需要构建自己的自定义 Julia 映像

于 2020-10-04T20:05:14.063 回答