学习Udacity上的DeepLearning视频,第一个assignment是tensorflow官方git上example里的1_notmnist
Problem 1
Let’s take a peek at some of the data to make sure it looks sensible. Each exemplar should be an image of a character A through J rendered in a different font. Display a sample of the images that we just downloaded. Hint: you can use the package IPython.display.
My Answer:
from IPython.display import Image
import random
def show_image(num_per_letter):
root = 'notMNIST_large'
for subroot in sorted(os.listdir(root)):
fulldir = os.path.join(root,subroot)
file = [os.path.join(fulldir,x) for x in random.sample(os.listdir(fulldir),3)
if os.path.isfile(os.path.join(fulldir,x))]
print(subroot+':')
for name in file:
display(Image(name))
show_image(5)
结果为每个字母随机显示5副图片