Comments (3)
@manuelbb-upb In the backward pass, you need to pass a Float32 value. So the last line should be changed to pullback_fn(1.0f0)
from raytracer.jl.
Thanks, I thought that the type was not important at that point ( I only used pullback()
for debugging anyways, it happened with Zygote's gradient
too).
But now something interesting has happened: After a restart of my computer I cannot reproduce the error using the minimal example provided above, it works with pullback_fn(1)
and pullback_fn(1.0f0)
.
However, my original script still does throw the MethodError. The complete script is
using RayTracer, Images, Zygote, Flux
cd(@__DIR__)
screen_size = ( w = 40, h = 40 )
orig_obj = load_obj( "teapot-low.obj" )
light = DistantLight(
Vec3(1.0f0),
100.0f0,
Vec3( 0.0f0, 1.0f0, 0.0f0 )
)
cam = Camera(
Vec3(1.0f0, 80.0f0, -1.0f0),
Vec3(0.0f0),
Vec3(0.0f0, 1.0f0, 0.0f0),
45.0f0,
1.0f0,
screen_size...
)
function render(camera_obj)
origin, direction = get_primary_rays( camera_obj );
return raytrace( origin, direction, orig_obj, light, origin, 2);
end
#utility functions
raw_to_num_array( raw_render ) = zeroonenorm(reshape(hcat(raw_render.x, raw_render.y, raw_render.z),(screen_size..., 3)))
raw_to_img( raw_render ) = get_image(raw_render, screen_size...)
num_arr_to_img( num_arr ) = colorview( RGB, permutedims( num_arr , (3,2,1) ) )
function move_cam(camera_obj, direction_vec::Vec3{Array{Float32,1}} )
# move camera relative to object instead of moving the move_object
moved_cam = Camera(
camera_obj.lookfrom - direction_vec,
camera_obj.lookat,
camera_obj.vfov,
camera_obj.focus,
camera_obj.fixedparams
)
end
# render target image for loss calculation
target_raw = render(cam)
target_num_array = raw_to_num_array(target_raw)
target_img =num_arr_to_img(target_num_array)
display(target_img)
function loss_fn( direction::Vec3 )
new_cam = move_cam(cam, direction)
new_raw = render( new_cam )
new_num_array = raw_to_num_array(new_raw)
return sum( (target_num_array .- new_num_array ).^2 )
end
pertubation = Vec3( Float32.(10 * rand(3) + (1 .+ rand(3)).^2)... )
opt = ADAM(1)
for i in 1:50
loss, back_fn = Zygote.pullback( pertubation ) do d
loss_fn(d)
end
@show loss
grad_vec = back_fn(1.0f0)
update!(opt, pertubation, grad_vec[1])
end
Applying my fix from the first post makes it work.
from raytracer.jl.
Interesting, there is nothing incorrect in your script, there must be some type promotion happening internally. It will take me some time to figure out what is the exact issue.
The fix you propose is kind of bypassing the issue, but will result in problems if we want to use Float64.
from raytracer.jl.
Related Issues (9)
- Possible to fix lighting and optimize polygon position? HOT 2
- inverse lighting example missing definition of `opt` HOT 1
- @nograd not defined when trying to run teapot_rendering.jl HOT 2
- Question about DTM rendering HOT 2
- TagBot trigger issue HOT 1
- Zygote.forward Usage in RayTracer.jl/docs/src/inverse_lighting.md HOT 1
- Mesh rendering HOT 2
- JuliaCon submission comments HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raytracer.jl.