NameError: name ‘ImageDataBunch’ is not defined - fast-ai

I am trying to use the below syntax on Colab but it returns NameError: name 'ImageDataBunch' is not defined
from fastai.vision import *
data = ImageDataBunch.from_folder('Kather_texture_2016_image_tiles_5000', valid_pct=0.2, seed=123)

Related

Error in MarkLogic Optic Query - to get percentage of occurrence of a record in a template view document

I am trying to find the percentage of a certain record based on a condition to the total no of that record . I am using optic query to get the result.
To be specific on the requirement :
Give a percentage of a certain record, when there is a condition, with the total number of that record available in the template view.
Here is my optic query which I am trying -
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy";
import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy";
declare option xdmp:mapping "false";
let $view := op:from-view("GTM2_Shipment", "Shipment_View")
let $Ancillary_QuotePrice := op:view-col("Shipment_View", "Ancillary_QuotePrice")
return $view
=> op:group-by((),(op:count("TotcountOfColumn", $Ancillary_QuotePrice),op:count("percentageCount", $Ancillary_QuotePrice)))
=> op:select(
op:as("CountOnCond", op:where(op:and((
op:gt($Ancillary_QuotePrice, 0),op:gt(ofn:format-dateTime(op:col('BookingCreateDt'), '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]')))
))
)
),
op:as("Percentage",op:divide(op:col("CountOnCond"),op:col("TotcountOfColumn")))
)
=> op:result()
It gives me this error -
1.0-ml] XDMP-TOOFEWARGS: (err:XPST0017) op:where(op:and((op:gt($countOfColumn, 0), op:gt(ofn:format-dateTime(op:col("BookingCreateDt"), "[Y0001]-[M01]-[D01]"), osql:dateadd("month", -6, ofn:format-dateTime(fn:current-dateTime(), "[Y0001]-[M01]-[D01]")))))) -- Too few args, expected 2 but got 1
Also please check if my query logic is correct or not.
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy";
import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy";
import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy";
declare option xdmp:mapping "false";
let $view := op:from-view("GTM2_Shipment", "Shipment_View")
let $Var1 := op:view-col("Shipment_View", "Ancillary_QuotePrice")
let $Var2 := op:view-col("Shipment_View", "Shipment_Ref")
return $view
=> op:group-by((),(op:count("Var2", $Var2),op:count("Var1", $Var1)))
=>op:select(op:as("multiply", op:divide(op:col("Var1"), op:col("Var2"))))
=>op:select(op:as("percentageFinal", op:multiply(100, op:col("multiply"))))
=> op:result()
Above is the straightforward percentage found for Var1 with total of Var2.
I want the condition of the Var1 to be added in the code. Where can I add the where condition please.
op:where() expect the first parameter to be the $plan. Typically, when chaining calls from a plan using => it is set as that first parameter for you, and you are then providing the subsequent parameters starting from the second parameter with what is explicitly set in the function call.
So, when attempting to apply op:where() as the expression for op:as() to bind to:
op:as("CountOnCond", op:where(op:and((
op:gt($Ancillary_QuotePrice, 0),op:gt(ofn:format-dateTime(op:col('BookingCreateDt'), '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]')))
))
)
the op:and() parameter being specified is the one and only parameter being specified, but op:where() has two required parameters.
That is why it throws the XDMP-TOOFEWARGS error.

Using local Julia modules in Pluto

What is the correct way to import local modules in Pluto v0.18.0 notebooks with Julia 1.7.2?
The using keyword adds exported members to the main namespace in Julia. Given a sample module, in foo.jl,
module Foo
export bar
function bar()
return "baz"
end
end
The following code cell works in a Pluto Notebook:
# "baz"
begin
include("./foo.jl")
using .Foo
bar()
end
However, if I attempt to call bar from another cell, I get the following error:
# UndefVarError: bar not defined
bar()
Though I notice that Foo.bar() does work.
How do I add my own modules in a way that I get access to their exported members directly in the notebook's namespace?
This discussion gives a possible solution. It describes a better way of getting the module reference than what I have in my question.
If the module is not the last definition in the file, the import function has to be redefined. A suggested name is to have a variant called "ingredients"
#ingredients (generic function with 1 method)
function ingredients(path::String)
# this is from the Julia source code (evalfile in base/loading.jl)
# but with the modification that it returns the module instead of the last object
name = Symbol(basename(path))
m = Module(name)
Core.eval(m,
Expr(:toplevel,
:(eval(x) = $(Expr(:core, :eval))($name, x)),
:(include(x) = $(Expr(:top, :include))($name, x)),
:(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, $name, x)),
:(include($path))))
m
end
Then the module can be loaded in like so (I don't know the reason why I have to say ingredients().Foo)
#Main.Foo.jl.Foo
Foo = ingredients("My Library/Foo.jl").Foo
and then with the module reference, you have to manually bring all exported variables into the global scope:
#bar = bar (generic function with 1 method)
bar = Foo.bar

How to make self defined enum type in module available in julia

I am trying to define an enum type in a module so I can use it in all my functions. When I export the module, I can only get the enum type, but the element in enumerate type can not be recognized.
module testaux
greet() = print("Hello World!")
#enum Stortype colMajor rowMajor
#enum Sorttype ascend descend nosort
end # module
after import testaux successfully, I can call greet() and recognize Stortype. But I failed to use Stortype to restrict my function argument by the following definition:
function t(a::Stortype)
println(a)
end
t(colMajor)
will complain colMajor not defined.

'UndefVarError: x not defined' when calling a macro outside of its module (Julia v1.1)

I'm trying to code a macro which calls a function defined within the same module (with Julia v1.1). I always get the ERROR: LoadError: UndefVarError: myModel not defined.
The code of the module is the following (Models.jl):
module Models
export Model
export createmodel
export add_variable
export #add_variable
mutable struct Model
variable_symbols::Dict{String, Symbol}
variable_data::Dict{Symbol, Array{Int64, 1}}
Model(; variable_symbols = Dict([]), variable_data = Dict([])) =
new(variable_symbols, variable_data)
Model(variable_symbols, variable_data) = new(variable_symbols,
variable_data)
end
function createmodel()
model = Model()
return model
end
function add_variable(model, label::String, value::Array{Int64, 1})
symbol = Symbol(label)
model.variable_symbols[label] = Symbol(symbol)
model.variable_data[symbol] = value
end
macro add_variable(model, var)
quote
add_variable($model, $(string(var)), $var)
end
end
end
The macro is called as following:
include("Models.jl")
using .Models
x = [1, 2, 3]
myModel = createmodel()
#add_variable(myModel, x)
show(myModel)
I know that this is an escaping/hygiene problem, but after trying many ideas I don't get the expected result. Up to now, my only way to get the expected result was to define the macro outside of the module to get: Model(Dict("x"=>:x), Dict(:x=>[1, 2, 3]))
You just need to escape the variables that get passed into the macro:
macro add_variable(model, var)
quote
add_variable($(esc(model)), $(string(var)), $(esc(var)))
end
end
All names in a macro are resolved in the context of the module its defined in unless you esc them — with an esc they're resolved in the context of the caller. You almost always want to esc the arguments to the macro. Names like add_variable, though, you want to resolve in the place where the macro itself was defined.

Creating an External Constructor for the Natural log of the Volume of a Cube

I am taking a Julia class and I am am trying to create a method to calculate the natural log of a user defined type.
I have created a parameterized type MyCube
type MyCube{T}
h::T
w::T
l::T
end
and I have created 2 instances of this type and i defined them as Float64 hoping this would resolve the issue, but it didnt
cube1 = MyCube{Float64}(2,3,2)
cube2 = MyCube{Float64}(4,3,2)
Now trying to define the method
import Base.log
log(u::MyCube) = MyCube(log(u.h * u.w * u.l))
log(cube1)
and when I try to run the run the method on the instance of the type cube1
log(cube1)
I get the following error
LoadError: MethodError: `convert` has no method matching convert(::Type{MyCube{T}}, ::Float64)
This may have arisen from a call to the constructor MyCube{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
MyCube{T}(::T, !Matched::T, !Matched::T)
call{T}(::Type{T}, ::Any)
convert{T}(::Type{T}, !Matched::T)
while loading In[33], in expression starting on line 2
in log at In[32]:2
Any help would be appreciated
log(u::MyCube) = MyCube(log(u.h * u.w * u.l))
Here you are you are trying to call a function (the type constructor for MyCube) on your cube1.
Just log(u::MyCube) = log(u.h * u.w * u.l)
Will add a new method for log to dispatch on your type MyCube!
Should be
log(u::MyCube) = log(u.h * u.w * u.l)

Resources