Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
carpedm20 committed Feb 7, 2016
1 parent 64c9ee7 commit 161501b
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 130 deletions.
Binary file added average.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def main(_):
[dcgan.h3_w, dcgan.h3_b, dcgan.g_bn3],
[dcgan.h4_w, dcgan.h4_b, None])

OPTION = 7
OPTION = 6
if OPTION == 0:
z_sample = np.random.uniform(-1, 1, size=(FLAGS.batch_size, dcgan.z_dim))
z_sample = np.random.uniform(-0.5, 0.5, size=(FLAGS.batch_size, dcgan.z_dim))
samples = sess.run(dcgan.sampler, feed_dict={dcgan.z: z_sample})
save_images(samples, [8, 8], './samples/test_%s.png' % strftime("%Y-%m-%d %H:%M:%S", gmtime()))
elif OPTION == 1:
values = np.arange(0, 1, 1./FLAGS.batch_size)
Expand Down Expand Up @@ -119,11 +120,12 @@ def main(_):
elif OPTION == 6:
image_set = []

z_idx = [[random.randint(0,99) for _ in xrange(10)] for _ in xrange(dcgan.z_dim)]
values = np.arange(0, 1, 1.0/FLAGS.batch_size).tolist()
z_idx = [[random.randint(0,99) for _ in xrange(10)] for _ in xrange(100)]

for idx in xrange(100):
print(" [*] %d" % idx)
z = np.random.uniform(-1, 1, size=(dcgan.z_dim))
z = np.random.uniform(-0.2, 0.2, size=(dcgan.z_dim))
z_sample = np.tile(z, (FLAGS.batch_size, 1))

for kdx, z in enumerate(z_sample):
Expand All @@ -134,7 +136,7 @@ def main(_):
save_images(image_set[-1], [8, 8], './samples/test_random_arange_%s.png' % (idx))

new_image_set = [merge(np.array([images[idx] for images in image_set]), [10, 10]) for idx in range(64) + range(63, -1, -1)]
make_gif(new_image_set, './samples/test_gif_merged_random.gif', duration=8)
make_gif(new_image_set, './samples/test_gif_merged_random.gif', duration=4)
elif OPTION == 7:
for _ in xrange(50):
z_idx = [[random.randint(0,99) for _ in xrange(10)] for _ in xrange(8)]
Expand Down
18 changes: 16 additions & 2 deletions web/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ canvas {
#colors {
overflow: hidden;
width: 90px;
height: 330px;
margin-left: 30px;
float: left;
}
Expand Down Expand Up @@ -246,6 +245,8 @@ a:focus {
}

.intro {
overflow: hidden;
position: relative;
display: table;
width: 100%;
height: auto;
Expand Down Expand Up @@ -472,4 +473,17 @@ body {
}

.tooltip > .tooltip-inner { background-color: white; color: black; }
.tooltip > .tooltip-arrow { border-bottom-color: white; color: black; }
.tooltip > .tooltip-arrow { border-bottom-color: white; color: black; }

.tooltip {
opacity: 0.95 !important;
}

.pixel-tooltip {
padding: 0px !important;
background-color: transparent !important;
}

.fa-5 {
font-size: 40px !important;
}
Binary file added web/img/average.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
196 changes: 129 additions & 67 deletions web/index.html

Large diffs are not rendered by default.

146 changes: 91 additions & 55 deletions web/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,94 @@ function rgb2hex(rgb){
("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : "";
}

var make_z = function(max_length, scale) {
var z = []
var scale = scale | 2;
while(z.length < max_length){
var randomnumber=Math.random() * scale;
var found=false;
for(var i=0;i<z.length;i++){
if(z[i]==randomnumber){found=true;break}
}
if(!found)z[z.length]=randomnumber;
}
return z;
}

var get_pixels = function() {
var x = new Array(100);
var frame = PIXEL.getCurrentFrame();

for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
var idx = i*10 + j;
if (frame.data[i][j] == "rgba(0, 0, 0, 0)") {
x[idx] = 1;
if (frame[i][j] == "rgba(0, 0, 0, 0)") {
x[idx] = 0;
} else {
x[idx] = parseInt(frame.data[i][j].substring(1));
x[idx] = ((parseInt(frame[i][j].substring(1,3) ,16)/255*2)-1)/2;
}
}
}
return x;
}

var recover_pixels = function(x) {
for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
var idx = i*10 + j;
x[idx] = ((x[idx] * 2) + 1) / 2 * 255;
}
}
return x;
}

var draw_pixels = function(x) {
var frame = PIXEL.getCurrentFrame();

for (var i=0; i < 10; i++) {
for (var j=0; j < 10; j++) {
var hex = Math.ceil(x[i*10+j]).toString(16);
PIXEL.setDraw(true);
PIXEL.doAction(i*20, j*20, "#" + hex + hex + hex);
PIXEL.setDraw(false);
}
}
}

var clip_pixel = function(x){
if(x>1) return 255;
else if(x<-1) return 0;
else return 255*(x+1.0)/2.0;
}

// mouse down event callback
function mouseDownCallback(e) {
PIXEL.setDraw(true);
var coordinates = getCoordinates(e);

PIXEL.doAction(coordinates.x, coordinates.y, currentColor);
}
function cloneCanvas(oldCanvas) {

// mouse move event callback
function mouseMoveCallback(e) {
var coordinates = getCoordinates(e);

PIXEL.doAction(coordinates.x, coordinates.y, currentColor);
e.preventDefault();
}
//create a new canvas
var newCanvas = document.createElement('canvas');
var context = newCanvas.getContext('2d');

// mouse up event callback
function mouseUpCallback() {
PIXEL.setDraw(false);
//set dimensions
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;

//apply the old canvas to the new one
context.drawImage(oldCanvas, 0, 0);

//return the new canvas
return newCanvas;
}

$(document).ready(function() {
draw_pixels(make_z(100, 255));

$('.slick').slick({
slidesToShow: 2,
autoplay: true,
dots: true,
autoplaySpeed: 3000,
responsive: [
{
breakpoint: 480,
breakpoint: 980,
settings: {
slidesToShow: 1,
slidesToScroll: 1
Expand All @@ -73,7 +108,14 @@ $(document).ready(function() {
autoplaySpeed: 3000,
responsive: [
{
breakpoint: 480,
breakpoint: 1200,
settings: {
slidesToShow: 5,
slidesToScroll: 5
}
},
{
breakpoint: 980,
settings: {
slidesToShow: 3,
slidesToScroll: 3
Expand Down Expand Up @@ -103,7 +145,13 @@ $(document).ready(function() {

var input = new convnetjs.Vol(1, 1, 100, 0.0);

var duplicates = [];
var pixels = [];

var draw = function() {
cur_pixel = get_pixels();
input.w = cur_pixel;

var output = net.forward(input);
var scale = 2;
var W = output.sx * scale;
Expand Down Expand Up @@ -132,19 +180,33 @@ $(document).ready(function() {
}
}
ctx.putImageData(g, 0, 0);

document.getElementById("images").appendChild(canv);

$(canv).attr('data-original-title', canvas[0].outerHTML)
.tooltip({html:true})
.hide()
.fadeIn(1000);
duplicates.push(cloneCanvas(document.getElementById("pixel")));
pixels.push(cur_pixel);

$(canv).tooltip({
html: true,
template: '<div class="tooltip"><div class="tooltip-inner pixel-tooltip"></div></div>',
title: function(e) {
var duplicated = duplicates[parseInt($(this).attr("id")) - 1];
return duplicated;
},
}).hide()
.attr("id", duplicates.length)
.fadeIn(1000)
.click(function() {
draw_pixels(recover_pixels(pixels[parseInt($(this).attr("id")) - 1]));
});
}

$("#fakeLoader").fadeOut(3000);

$("#draw").click(draw);
$("#shuffle").click(draw);
$("#shuffle").click(function() {
draw_pixels(make_z(100, 255));
draw();
});
});


Expand Down Expand Up @@ -196,7 +258,7 @@ var currentColor = "#000000",
function mouseDownCallback(e) {
PIXEL.setDraw(true);
var coordinates = getCoordinates(e);

PIXEL.doAction(coordinates.x, coordinates.y, currentColor);
}

Expand Down Expand Up @@ -224,32 +286,6 @@ canvas.bind('touchstart', mouseDownCallback).bind('touchmove', mouseMoveCallback
$(document).mouseup(mouseUpCallback);
$(document).bind('touchend', mouseUpCallback);

// controls
$("#clear").click(function() {
if(confirm("Sure?")) {
clearAll();
}
});

function clearAll() {
var framesLength = PIXEL.getFramesLength();
for(var i = framesLength-1; i >= 0; i--) {
PIXEL.log('REMOVE ' + i + ' FRAME OF ' + PIXEL.getFramesLength() + ' FRAMES!');
PIXEL.clearCanvasAt(i);
PIXEL.removeFrame(i);
disable($(".frame[data-frame=" + i + "]"));
}
PIXEL.setCurrentFrame(0);

deactivate($(".frame.active"));
activate($(".frame[data-frame=0]"));
enable($(".frame[data-frame=0]"));
disable($(".remove_frame"));
enable($(".add_frame"));

copyFrameIndex = -1;
}

$(".action.selectable").click(function() {
PIXEL.setAction($(this).data('action'));

Expand Down
5 changes: 4 additions & 1 deletion web/js/convnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ var convnetjs = convnetjs || { REVISION: 'ALPHA' };
}

function standardDeviation(v, nChannel){
var values = v.slice();
var values = new Float64Array(v.length);
for(var i=0;i<v.length;i++) {
values[i] = v[i];
}
var avgs = average(values, nChannel);

for(var i=0; i < values.length; i++) {
Expand Down
Binary file added web/videos/random.mp4
Binary file not shown.

0 comments on commit 161501b

Please sign in to comment.