-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
51 lines (43 loc) · 1.81 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- encoding: utf-8 -*-
"""
@Author : zYx.Tom
@Contact : 526614962@qq.com
@site : https://zhuyuanxiang.github.io
---------------------------
@Software : PyCharm
@Project : Dive-into-Deep-Learning
@File : sec0202.py
@Version : v0.1
@Time : 2020-12-27 9:25
@License : (C)Copyright 2018-2020, zYx.Tom
@Reference : 《动手学深度学习》
@Desc : Sec
@小结:
"""
import d2lzh as d2l
import mxnet as mx
import zipfile
import numpy as np
from mxnet import autograd, gluon, image, init, nd, ndarray
from mxnet.gluon import data as gdata, loss as gloss, nn
from tools import beep_end, show_subtitle, show_title, show_figures, get_root_path
# ----------------------------------------------------------------------
def load_data_jay_lyrics():
"""Load the Jay Chou lyric data set (available in the Chinese book)."""
with zipfile.ZipFile(get_root_path() + 'data/jaychou_lyrics.txt.zip') as zin:
with zin.open('jaychou_lyrics.txt') as f:
corpus_chars = f.read().decode('utf-8')
corpus_chars = corpus_chars.replace('\n', ' ').replace('\r', ' ')
corpus_chars = corpus_chars[0:10000]
idx_to_char = list(set(corpus_chars))
char_to_idx = dict([(char, i) for i, char in enumerate(idx_to_char)])
vocab_size = len(char_to_idx)
corpus_indices = [char_to_idx[char] for char in corpus_chars]
return corpus_indices, char_to_idx, idx_to_char, vocab_size
# ----------------------------------------------------------------------
def get_data_ch7():
data = np.genfromtxt(get_root_path() + "data/airfoil_self_noise.dat", delimiter='\t')
data = (data - data.mean(axis=0)) / data.std(axis=0)
return nd.array(data[:1500, :-1]), nd.array(data[:1500, -1])
def get_image(filename):
return image.imread(get_root_path() + filename)