VisualModule
Visualize image dataset. Currently support MNIST and CIFAR10. visualize_dataset takes 2 arguments:
imgsof type Dense.Ndarray.D.arr,len, of type int, for showinglenxlenimages sample from theimgs
| #!/usr/bin/env owl | |
| open Owl | |
| let visualize_dataset x len = | |
| assert( len > 1 && len < 100 ); | |
| let num = len * len in | |
| let mats = Array.make num (Dense.Matrix.D.zeros 1 1) in | |
| for i = 0 to num - 1 do | |
| let fig = Dense.Ndarray.D.get_slice_simple [[i];[];[]] x | |
| |> Dense.Ndarray.D.squeeze | |
| |> Dense.Matrix.D.of_ndarray | |
| in | |
| mats.(i) <- fig; | |
| done; | |
| let mats2 = Array.make len (Dense.Matrix.D.zeros 1 1) in | |
| for i = 0 to (len-1) do | |
| let m = Array.sub mats (i*len) len | |
| |> Dense.Matrix.D.concatenate ~axis:0 | |
| in | |
| mats2.(i) <- m | |
| done; | |
| let img = Dense.Matrix.D.concatenate ~axis:1 mats2 in | |
| Plot.image img | |
| (* | |
| let x, _, _ = Dataset.load_cifar_test_data () in | |
| let x = Dense.Ndarray.Generic.cast_s2d x | |
| |> Dense.Ndarray.D.slice [[];[];[];[0]] | |
| |> Dense.Ndarray.D.squeeze | |
| in | |
| visualize_dataset x 10 | |
| *) |