Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 152

javaalpha/ticket

forked from 千寻啊千寻/ticket
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (2)
Tags (3)
master
develop
20190904
20190802
20190719
master
Branches (2)
Tags (3)
master
develop
20190904
20190802
20190719
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (2)
Tags (3)
master
develop
20190904
20190802
20190719
ticket
/
python
/
mlearn.py
ticket
/
python
/
mlearn.py
mlearn.py 5.57 KB
Copy Edit Raw Blame History
千寻啊千寻 authored 2019年07月16日 16:17 +08:00 . 初次提交抢票
# coding: utf-8
import pathlib
import cv2
import matplotlib.pyplot as plt
import numpy as np
from keras import backend as K
from keras import layers
from keras import models
from keras.callbacks import ReduceLROnPlateau
from keras.utils import to_categorical
def load_data(fn='texts.npz', to=False):
data = np.load(fn)
texts, labels = data['texts'], data['labels']
texts = texts / 255.0
_, h, w = texts.shape
texts.shape = (-1, h, w, 1)
if to:
labels = to_categorical(labels)
n = int(texts.shape[0] * 0.9) # 90%用于训练,10%用于测试
return (texts[:n], labels[:n]), (texts[n:], labels[n:])
def savefig(history, fn='loss.jpg', start=2):
# 忽略起点
loss = history.history['loss'][start - 1:]
val_loss = history.history['val_loss'][start - 1:]
epochs = list(range(start, len(loss) + start))
plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='Validation loss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.savefig(fn)
def main():
(train_x, train_y), (test_x, test_y) = load_data()
model = models.Sequential([
layers.Conv2D(64, (3, 3), padding='same', activation='relu', input_shape=(None, None, 1)),
layers.MaxPooling2D(), # 19 -> 9
layers.Conv2D(64, (3, 3), padding='same', activation='relu'),
layers.MaxPooling2D(), # 9 -> 4
layers.Conv2D(64, (3, 3), padding='same', activation='relu'),
layers.MaxPooling2D(), # 4 -> 2
layers.GlobalAveragePooling2D(),
layers.Dropout(0.25),
layers.Dense(64, activation='relu'),
layers.Dense(80, activation='softmax'),
])
model.summary()
model.compile(optimizer='rmsprop',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# 当标准评估停止提升时,降低学习速率
reduce_lr = ReduceLROnPlateau(verbose=1)
history = model.fit(train_x, train_y, epochs=100,
validation_data=(test_x, test_y),
callbacks=[reduce_lr])
savefig(history, start=10)
model.save('model.v1.0.h5', include_optimizer=False)
def load_data_v2():
(train_x, train_y), (test_x, test_y) = load_data(to=True)
# 这里是统计学数据
(train_v2_x, train_v2_y), (test_v2_x, test_v2_y) = load_data('texts.v2.npz')
# 合并
train_x = np.concatenate((train_x, train_v2_x))
train_y = np.concatenate((train_y, train_v2_y))
test_x = np.concatenate((test_x, test_v2_x))
test_y = np.concatenate((test_y, test_v2_y))
return (train_x, train_y), (test_x, test_y)
def acc(y_true, y_pred):
return K.cast(K.equal(K.argmax(y_true + y_pred, axis=-1),
K.argmax(y_pred, axis=-1)),
K.floatx())
def main_v19(): # 1.9
(train_x, train_y), (test_x, test_y) = load_data_v2()
model = models.load_model('model.v1.0.h5')
model.compile(optimizer='RMSprop',
loss='categorical_hinge',
metrics=[acc])
reduce_lr = ReduceLROnPlateau(verbose=1)
history = model.fit(train_x, train_y, epochs=100,
validation_data=(test_x, test_y),
callbacks=[reduce_lr])
savefig(history)
model.save('model.v1.9.h5', include_optimizer=False)
def main_v20():
(train_x, train_y), (test_x, test_y) = load_data()
model = models.Sequential([
layers.Conv2D(64, (3, 3), activation='relu', padding='same', input_shape=(None, None, 1)),
layers.MaxPooling2D(), # 19 -> 9
layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
layers.MaxPooling2D(), # 9 -> 4
layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
layers.MaxPooling2D(), # 4 -> 2
layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
layers.MaxPooling2D(), # 2 -> 1
layers.GlobalAveragePooling2D(),
layers.Dropout(0.25),
layers.Dense(64, activation='relu'),
layers.Dense(80, activation='softmax'),
])
model.summary()
model.compile(optimizer='rmsprop',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_x, train_y, epochs=10,
validation_data=(test_x, test_y))
(train_x, train_y), (test_x, test_y) = load_data_v2()
model.compile(optimizer='rmsprop',
loss='categorical_hinge',
metrics=[acc])
reduce_lr = ReduceLROnPlateau(verbose=1)
history = model.fit(train_x, train_y, epochs=100,
validation_data=(test_x, test_y),
callbacks=[reduce_lr])
savefig(history)
# 保存,并扔掉优化器
model.save('model.v2.0.h5', include_optimizer=False)
def predict(texts):
model = models.load_model('model.h5')
texts = texts / 255.0
_, h, w = texts.shape
texts.shape = (-1, h, w, 1)
labels = model.predict(texts)
return labels
def _predict():
texts = np.load('data.npy')
labels = predict(texts)
np.save('labels.npy', labels)
def show():
texts = np.load('data.npy')
labels = np.load('labels.npy')
labels = labels.argmax(axis=1)
pathlib.Path('classify').mkdir(exist_ok=True)
for idx, (text, label) in enumerate(zip(texts, labels)):
# 使用聚类结果命名
fn = f'classify/{label}.{idx}.jpg'
cv2.imwrite(fn, text)
if __name__ == '__main__':
main()
# main_v2()
_predict()
show()
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

【12306 购票辅助】这是一个牛逼的全自动购票系统,该系统为 Spring Boot 编写的后端服务,就不需要天天盯着 12306 官网查询余票了,用起来很爽,保证不收集任何敏感信息,真的。QQ群:852214454
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/javaalpha/ticket.git
git@gitee.com:javaalpha/ticket.git
javaalpha
ticket
ticket
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /