Comments (9)
Hey,
So my solution to this was to do the following.
`
hexval = "{0:#0{1}x}".format(len(FileList),10) # number of files in HEX
# header for label array
header = array('B')
header.extend([0,0,8,1])
header.append(int('0x'+hexval[2:][:2],16))
header.append(int('0x'+hexval[4:][:2],16))
header.append(int('0x'+hexval[6:][:2],16))
header.append(int('0x'+hexval[8:][:2],16))
data_label = header + data_label
hexval = "{0:#0{1}x}".format(width,10) # width in HEX
header.append(int('0x'+hexval[2:][:2],16))
header.append(int('0x'+hexval[4:][:2],16))
header.append(int('0x'+hexval[6:][:2],16))
header.append(int('0x'+hexval[8:][:2],16))
hexval = "{0:#0{1}x}".format(height,10) # height in HEX
header.append(int('0x'+hexval[2:][:2],16))
header.append(int('0x'+hexval[4:][:2],16))
header.append(int('0x'+hexval[6:][:2],16))
header.append(int('0x'+hexval[8:][:2],16))
`
from jpg-png-to-mnist-nn-format.
https://github.com/gskielian/JPG-PNG-to-MNIST-NN-Format/issues/3
this can solve my problem!!
from jpg-png-to-mnist-nn-format.
Still facing this issue and the above link does not work.
from jpg-png-to-mnist-nn-format.
is this error solved yet?? cause i am getting this same problem....
from jpg-png-to-mnist-nn-format.
I am having the same issue. The code you provided above did not help in my case. I have an image size of 800x500.
from jpg-png-to-mnist-nn-format.
@ghulammustufa31 Did you figure it out? I am stuck on this
from jpg-png-to-mnist-nn-format.
#this worked for me
import os
from PIL import Image
from array import *
from random import shuffle
#WARNING: resize images first
Load from and save to
Names = [['./test-imgs-rot','test']]
for name in Names:
data_image = array('B')
data_label = array('B')
FileList = []
for dirname in os.listdir(name[0])[:]:
path = os.path.join(name[0],dirname)
for filename in os.listdir(path):
if filename.endswith(".png"):
FileList.append(os.path.join(name[0],dirname,filename))
Usefull for further segmenting the validation set
for filename in FileList:
label = int(filename.split('/')[2])
Im = Image.open(filename)
pixel = Im.load()
width, height = Im.size
for x in range(0,width):
for y in range(0,height):
data_image.append(pixel[y,x])
data_label.append(label) # labels start (one unsigned byte each)
hexval = "{0:#0{1}x}".format(len(FileList),10) # number of files in HEX
# header for label array
header = array('B')
header.extend([0,0,8,1,0,0])
header.append(int('0x' + hexval[2:][:2], 16))
header.append(int('0x' + hexval[4:][:2], 16))
header.append(int('0x' + hexval[6:][:2], 16))
header.append(int('0x' + hexval[8:][:2], 16))
data_label = header + data_label
# additional header for images array
hexval = "{0:#0{1}x}".format(width, 10) # width in HEX
header.append(int('0x' + hexval[2:][:2], 16))
header.append(int('0x' + hexval[4:][:2], 16))
header.append(int('0x' + hexval[6:][:2], 16))
header.append(int('0x' + hexval[8:][:2], 16))
hexval = "{0:#0{1}x}".format(height, 10) # height in HEX
header.append(int('0x' + hexval[2:][:2], 16))
header.append(int('0x' + hexval[4:][:2], 16))
header.append(int('0x' + hexval[6:][:2], 16))
header.append(int('0x' + hexval[8:][:2], 16))
if max([width,height]) <= 256:
header.extend([0,0,0,width,0,0,0,height])
else:
raise ValueError('Image exceeds maximum size: 256x256 pixels');
header[3] = 3 # Changing MSB for image data (0x00000803)
data_image = header + data_image
output_file = open(name[1] + '-images-rot-idx3-ubyte', 'wb')
data_image.tofile(output_file)
output_file.close()
output_file = open(name[1]+'-labels-rot-idx1-ubyte', 'wb')
data_label.tofile(output_file)
output_file.close()
gzip resulting files
for name in Names:
os.system('gzip '+name[1]+'-images-idx3-ubyte')
os.system('gzip '+name[1]+'-labels-idx1-ubyte')
from jpg-png-to-mnist-nn-format.
@KumarLamic why did you change the from 6 to 10 in hexval
I cant reshape my data now do you have a solution
from jpg-png-to-mnist-nn-format.
that was just a random trial and it worked for me
from jpg-png-to-mnist-nn-format.
Related Issues (20)
- 15 for dirname in os.listdir(name[0])[1:]: # [1:] Excludes .DS_Store from Mac OS
- limited to 28x28 HOT 2
- question about array typecode of data_image HOT 1
- Please help my data is text i want do cnn and lstm
- resize-script.sh error: invalid parameter HOT 1
- Not taking in images from folder 22 HOT 1
- How to use created dataset in others neural networks??? HOT 1
- 'gzip' is not recognized as an internal or external command HOT 1
- Bug/Problem Code lines 15, 46 HOT 1
- NameError: name 'width' is not defined HOT 2
- Size of the output for larger number of images HOT 1
- please help in solving this error HOT 2
- Why labels printed are always 1? HOT 2
- two or three classifications
- Need help with this issue HOT 1
- TypeError: an integer is required (got type tuple) data_image.append(pixel[y,x]) HOT 3
- data_image.append(pixel[y,x]) IndexError: image index out of range HOT 3
- resize-script.sh
- placeholder.txt 这个文件是写什么的?
- some questions please look this:
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 jpg-png-to-mnist-nn-format.