New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support frames #134
Comments
If I'm understanding correctly, you could: 1) Create a new statimport OnlineStatsBase
mutable struct ElementwiseStat{T<:OnlineStat} <: OnlineStat{Matrix}
value::Matrix{T}
n::Int
end
ElementwiseStat(n, p, stat = Mean()) = ElementwiseStat([copy(stat) for i in 1:n, j in 1:p], 0)
OnlineStatsBase._fit!(o::ElementwiseStat, y) = (fit!.(o.value, y); o.n += 1)
fit!(ElementwiseStat(10, 10), [rand(10,10) for i in 1:3]) 2) Use Broadcasting
|
This is exactly what I wanted, awesome, thank you! function fun()
μ = zeros(sz...)
for i in readdir(imgs)
μ .+= Float64.(Gray.(load(joinpath(imgs, i))))
end
μ ./= length(readdir(imgs))
end Also, since the elements in the images are typically julia> s = [FTSeries(Mean(); transform = x -> Float64(Gray(x))) for i in 1:5, j in 1:5]
5×5 Array{FTSeries{Number,Tuple{Mean{EqualWeight}},getfield(OnlineStats, Symbol("##16#18")),getfield(Main, Symbol("##26#28"))},2}:
FTSeries
└── Mean: n=0 | value=0.0 … FTSeries
└── Mean: n=0 | value=0.0
FTSeries
└── Mean: n=0 | value=0.0 FTSeries
└── Mean: n=0 | value=0.0
FTSeries
└── Mean: n=0 | value=0.0 FTSeries
└── Mean: n=0 | value=0.0
FTSeries
└── Mean: n=0 | value=0.0 FTSeries
└── Mean: n=0 | value=0.0
FTSeries
└── Mean: n=0 | value=0.0 FTSeries
└── Mean: n=0 | value=0.0
julia> fit!.(s, rand(RGB{N0f8}, 5, 5))
ERROR: MethodError: no method matching iterate(::RGB{Normed{UInt8,8}})
Closest candidates are:
iterate(::Core.SimpleVector) at essentials.jl:578
iterate(::Core.SimpleVector, ::Any) at essentials.jl:578
iterate(::ExponentialBackOff) at error.jl:171
...
Stacktrace:
[1] fit!(::FTSeries{Number,Tuple{Mean{EqualWeight}},getfield(OnlineStats, Symbol("##16#18")),getfield(Main, Symbol("##26#28"))}, ::RGB{Normed{UInt8,8}}) at /home/yakir/.julia/packages/OnlineStatsBase/Se4Hf/src/OnlineStatsBase.jl:76
[2] _broadcast_getindex at ./broadcast.jl:574 [inlined]
[3] getindex at ./broadcast.jl:507 [inlined]
[4] copy at ./broadcast.jl:758 [inlined]
[5] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2},Nothing,typeof(fit!),Tuple{Array{FTSeries{Number,Tuple{Mean{EqualWeight}},getfield(OnlineStats, Symbol("##16#18")),getfield(Main, Symbol("##26#28"))},2},Array{RGB{Normed{UInt8,8}},2}}}) at ./broadcast.jl:724
[6] top-level scope at none:0 But it's still trying to iterate before applying the transform. Any way I can flag |
I'd guess swapping out the broadcasting with an explicit loop would help. You're also keeping track of less state/calculating fewer things in your function than Making |
This is great, thank you so much for the help. |
Thanks to both of you for raising and providing solutions to this issue. FWIW I benchmarked the 2 approaches and found they were pretty much the same in terms of memory and performance.
|
Wow, that is damn near identical. Awesome. |
I often need to do some stats on image frames from some video. Sometimes the size of the images, their number, and their encoding means it's too big to hold in memory. So... Can we have the stats hold whole frames (i.e. arrays of colors, or just arrays of floats)?
So I could:
and have it return the mean across the outer dimension (so it's size would be 10 x 10)?
The text was updated successfully, but these errors were encountered: