Sunday, July 12, 2020
Show line number in the jupyter notebook
If you press a key 'L' in the jupyter notebook then you can see the line number in the editor.
Sunday, July 5, 2020
python binary write/read example
import numpy as np
import json
def read32(bs):
data = bs.read(4)
return int.from_bytes(data, byteorder='big', signed=False)
def write32(bs, int_data):
bs.write(int_data.to_bytes(4, byteorder='big', signed=False))
def writeTest():
trainImageFile = open('eyedata_set/train-images.ubyte', 'wb')
count = 4
width = 1024
height = 768
write32(trainImageFile, count)
write32(trainImageFile, width)
write32(trainImageFile, height)
trainImageFile.close()
print('[DONE] write test')
def readTest():
trainImageFile = open('eyedata_set/train-images.ubyte', 'rb')
count = read32(trainImageFile)
width = read32(trainImageFile)
height = read32(trainImageFile)
trainImageFile.close()
print('[DONE] read test')
print('{}, {}, {}'.format(count, width, height))
import json
def read32(bs):
data = bs.read(4)
return int.from_bytes(data, byteorder='big', signed=False)
def write32(bs, int_data):
bs.write(int_data.to_bytes(4, byteorder='big', signed=False))
def writeTest():
trainImageFile = open('eyedata_set/train-images.ubyte', 'wb')
count = 4
width = 1024
height = 768
write32(trainImageFile, count)
write32(trainImageFile, width)
write32(trainImageFile, height)
trainImageFile.close()
print('[DONE] write test')
def readTest():
trainImageFile = open('eyedata_set/train-images.ubyte', 'rb')
count = read32(trainImageFile)
width = read32(trainImageFile)
height = read32(trainImageFile)
trainImageFile.close()
print('[DONE] read test')
print('{}, {}, {}'.format(count, width, height))
Wednesday, July 1, 2020
MNIST 데이터 읽어서 이미지로 저장하기
train-images.idx3-ubyte 파일은 http://yann.lecun.com/exdb/mnist/에서 받으면 되고
보통은 만들어진 파서 사용하면 되지만 파이썬 공부도 할겸. 직접 만들어서 처리.
# train-images.idx3-ubyte
from PIL import Image
f = open('train-images.idx3-ubyte', 'rb')
#[offset] [type] [value] [description]
#0000 32 bit integer 0x00000803(2051) magic number
#0004 32 bit integer 60000 number of images
#0008 32 bit integer 28 number of rows
#0012 32 bit integer 28 number of columns
#0016 unsigned byte ?? pixel
#0017 unsigned byte ?? pixel
#........
#xxxx unsigned byte ?? pixel
#Pixels are organized row-wise. Pixel values are 0
def read32(bs):
data = bs.read(4)
return int.from_bytes(data, byteorder='big', signed=False)
magic = read32(f)
imageCount = read32(f)
imageRow = read32(f)
imageCol = read32(f)
for i in range(0,imageCount):
# 루프를 돌면서 28x28개수만큼 픽셀을 읽는다.
imageBuffer = f.read(28*28)
image = Image.frombytes('L', (28, 28), imageBuffer, 'raw')
image.save('extracted/' + str(i) + '.jpg', 'JPEG')
print('[DONE] Extracted all the images!')
f.close()
보통은 만들어진 파서 사용하면 되지만 파이썬 공부도 할겸. 직접 만들어서 처리.
# train-images.idx3-ubyte
from PIL import Image
f = open('train-images.idx3-ubyte', 'rb')
#[offset] [type] [value] [description]
#0000 32 bit integer 0x00000803(2051) magic number
#0004 32 bit integer 60000 number of images
#0008 32 bit integer 28 number of rows
#0012 32 bit integer 28 number of columns
#0016 unsigned byte ?? pixel
#0017 unsigned byte ?? pixel
#........
#xxxx unsigned byte ?? pixel
#Pixels are organized row-wise. Pixel values are 0
def read32(bs):
data = bs.read(4)
return int.from_bytes(data, byteorder='big', signed=False)
magic = read32(f)
imageCount = read32(f)
imageRow = read32(f)
imageCol = read32(f)
for i in range(0,imageCount):
# 루프를 돌면서 28x28개수만큼 픽셀을 읽는다.
imageBuffer = f.read(28*28)
image = Image.frombytes('L', (28, 28), imageBuffer, 'raw')
image.save('extracted/' + str(i) + '.jpg', 'JPEG')
print('[DONE] Extracted all the images!')
f.close()
Tuesday, June 30, 2020
Python single line for loop
# example of single line for loop
x = [1,2,3,4]
print( sum(e for e in x) )
x = [1,2,3,4]
print( sum(e for e in x) )
I can get 10. What if we don't have a single line for loop?
s = 0
for e in x:
s += e
print(s)
Wednesday, May 20, 2020
Selector, Sequence
Selector : Executes all the commands until it finds a success.
Sequence : Executes all the command until it finds a fail.
Tuesday, May 12, 2020
Data compression needs!
Many people are not interested about the data compression but it is important!
Recently I'm working on a project which is using GLTF and there is a library 'draco' but it seems animation data compression feature is a little bit missing as expected.
If the model has really big animations then size of the model will be big. This is not acceptable in some cases where passing the model data via network and so on.
I hope someone should be working on this issue ASAP! then you will get a credit!
Recently I'm working on a project which is using GLTF and there is a library 'draco' but it seems animation data compression feature is a little bit missing as expected.
If the model has really big animations then size of the model will be big. This is not acceptable in some cases where passing the model data via network and so on.
I hope someone should be working on this issue ASAP! then you will get a credit!
Thursday, May 7, 2020
Logarithmic Depth Buffer
If your model is big then you should use logarithmic depth buffer like down below
renderer = new THREE.WebGLRenderer( { antialias: true, logarithmicDepthBuffer: true } );
or just scale down the models. :)
Subscribe to:
Posts (Atom)
Task in UnrealEngine
https://www.youtube.com/watch?v=1lBadANnJaw
-
Unity released very good FPS example for people and I decided to analysis how they make this. Personally I wanted to show you how I analys...
-
Because nature of rotation angle, when we interpolate angles we could have some problems. For instance we have angle A0 and A1. A0 is -...
-
For instance I have 45 degree rotation quaternion p. and if I take p ^ (1/3) then I'll get 15 degree rotation quaternion. This is geomet...