Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
560 changes: 560 additions & 0 deletions 操作日志/get_the_flag.data

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions 操作日志/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
每行数据共58行,分别是:
| |单词出现频率|字符出现频率|平均词长|最长词长|总词长|分类|
|----|----|----|----|----|----|----|
|个数|48|6|1|1|1|1|
|类型|实数|实数|实数|整数|整数|布尔|
Answer:10001001110101110100111011011100100101111110000011001001
434 changes: 434 additions & 0 deletions 操作日志/tensorflow.ipynb

Large diffs are not rendered by default.

1,377 changes: 1,377 additions & 0 deletions 操作日志/test.data

Large diffs are not rendered by default.

3,224 changes: 3,224 additions & 0 deletions 操作日志/train.data

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import tensorflow as tf
# import os
# os.system('cls')

NUM_CLASSES = 30 # 10分类

labels = list(range(0,30,1)) # sample label
print("labels",labels)

batch_size = tf.size(labels) # get size of labels : 4

labels = tf.expand_dims(labels, 1) # 增加一个维度

indices = tf.expand_dims(tf.range(0, batch_size,1), 1) #生成索引
concated = tf.concat([indices, labels] , 1) #作为拼接
onehot_labels = tf.sparse_to_dense(concated, tf.stack([batch_size, NUM_CLASSES]), 1.0, 0.0) # 生成one-hot编码的标签

with tf.Session() as ssess:
print("labels",labels.eval())
print("indices",indices.eval())
print("concated",concated.eval())
print(onehot_labels[0])

Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
'''Train a simple deep CNN on the CIFAR10 small images dataset.

It gets to 75% validation accuracy in 25 epochs, and 79% after 50 epochs.
(it's still underfitting at that point, though).
'''

from __future__ import print_function
import keras
from keras.datasets import cifar10
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
import os

batch_size = 32 #批尺度——梯度下降法
# batch_size=1
# batch_size=N ( N为总数量 )
# batch_size=n ( n < N )

num_classes = 10 #
epochs = 100 #
data_augmentation = True
num_predictions = 20
save_dir = os.path.join(os.getcwd(), 'saved_models')
model_name = 'keras_cifar10_trained_model.h5'

# The data, split between train and test sets:
# 数据分为训练集和测试集:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# Convert class vectors to binary class matrices.
# 将类向量转换为二进制类矩阵。
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

model = Sequential()
model.add(Conv2D(32, (3, 3), padding='same',
input_shape=x_train.shape[1:]))
model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))

# initiate RMSprop optimizer
# 启动RMSprop优化器
opt = keras.optimizers.rmsprop(lr=0.0001, decay=1e-6)

# Let's train the model using RMSprop
# 我们使用RMSprop来训练模型
model.compile(loss='categorical_crossentropy',
optimizer=opt,
metrics=['accuracy'])

x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255

if not data_augmentation:
print('Not using data augmentation.')
model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(x_test, y_test),
shuffle=True)
else:
print('Using real-time data augmentation.')
# This will do preprocessing and realtime data augmentation:
# 这将做预处理和实时数据增强:
# 在深度学习中,我们经常需要用到一些技巧(比如将图片进行旋转,翻转等)来进行data augmentation, 来减少过拟合。
datagen = ImageDataGenerator(
featurewise_center=False, # set input mean to 0 over the dataset
# 在数据集上设置输入均值为0
samplewise_center=False, # set each sample mean to 0
# 将每个样本均值设置为0
featurewise_std_normalization=False, # divide inputs by std of the dataset
# 按照数据集的std(标准)分割输入
samplewise_std_normalization=False, # divide each input by its std
#
zca_whitening=False, # apply ZCA whitening
#

rotation_range=0, # randomly rotate images in the range (degrees, 0 to 180)
# 整数,数据提升时图片随机转动的角度
width_shift_range=0.1, # randomly shift images horizontally (fraction of total width)
# 浮点数,图片宽度的某个比例,数据提升时图片水平偏移的幅度`
height_shift_range=0.1, # randomly shift images vertically (fraction of total height)
# 浮点数,图片高度的某个比例,数据提升时图片竖直偏移的幅度
horizontal_flip=True, # randomly flip images
# 布尔值,进行随机水平翻转
vertical_flip=False # randomly flip images
# 布尔值,进行随机竖直翻转
)

# Compute quantities required for feature-wise normalization
# 计算功能所需的标准化所需的数量
# (std, mean, and principal components if ZCA whitening is applied).
# (如果应用ZCA白化,则为标准,平均和主要成分).
datagen.fit(x_train)

# Fit the model on the batches generated by datagen.flow().
# 将模型放在由 datagen.flow() 生成的批处理上。
model.fit_generator(datagen.flow(x_train, y_train,
batch_size=batch_size),
epochs=epochs,
validation_data=(x_test, y_test),
workers=4)

# Save model and weights
# 保存模型和权重
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
model_path = os.path.join(save_dir, model_name)
model.save(model_path)
print('Saved trained model at %s ' % model_path)

# Score trained model.
# 评分训练模型
scores = model.evaluate(x_test, y_test, verbose=1)
print('Test loss:', scores[0])
print('Test accuracy:', scores[1])
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-



from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.utils import np_utils
from keras import backend as K


Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# encoding: utf-8
'''
1、读取指定目录下的所有文件
2、读取文件,正则匹配出需要的内容,获取文件名
3、打开此文件(可以选择打开可以选择复制到别的地方去)
'''
import os.path
import sys
import re

# 遍历指定目录,显示目录下的所有文件名
def eachFile(filepath):
pathDir = os.listdir(filepath)
for allDir in pathDir:
print(allDir)
# child = os.path.join('%s\%s' % (filepath, allDir))
# if os.path.isfile(child):
# readFile(child)
# # print child.decode('gbk') # .decode('gbk')是解决中文显示乱码问题
# continue
# eachFile(child)

# # 遍历出结果 返回文件的名字
# def readFile(filenames):
# fopen = open(filenames, 'r', encoding='UTF-8') # r 代表read
# fileread = fopen.read()
# fopen.close()
# t=re.search(r'clearSpitValve',fileread)
# if t:
# # print "匹配到的文件是:"+filenames
# arr.append(filenames)

if __name__ == "__main__":
print('目前系统的编码为:',sys.getdefaultencoding())

filenames = "Data/logos/" # refer root dir
arr=[]
eachFile(filenames)
for i in arr:
print(i)

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# import json

# def myJsonLoad(filePath):
# '''把文件打开从字符串转换成数据类型'''
# with open(filePath,'rb') as load_file:
# load_dict = json.load(load_file)
# return load_dict

# logo_id =myJsonLoad('Data/logo_30/id_label.json')
# print(logo_id)




# import re
# allDir = 'aodi.500_0aic_QXOX3HGW_0DHP431L.jpg'
# theTpye = re.split('\.',allDir )[0]
# print(theTpye)


# import tensorflow as tf
# def myOneHot(num_classes):
# NUM_CLASSES = num_classes # 分类个数

# labels = list(range(0,num_classes,1)) # sample label

# batch_size = tf.size(labels) # get size of labels : 4

# labels = tf.expand_dims(labels, 1) # 增加一个维度
# indices = tf.expand_dims(tf.range(0, batch_size,1), 1) #生成索引
# concated = tf.concat([indices, labels] , 1) #作为拼接
# onehot_labels = tf.sparse_to_dense(concated, tf.stack([batch_size, NUM_CLASSES]), 1.0, 0.0) # 生成one-hot编码的标签
# with tf.Session() as ssess:
# # print(onehot_labels.eval())
# return onehot_labels.eval()

# ontHot = myOneHot(30)
# print(ontHot[1])



# import tensorflow as tf
# x = tf.placeholder(tf.float32,[None, 784*3])
# data = tf.reshape(x, [-1, 28, 28, 3]) #最后一维代表通道数目,如果是rgb则为3

# print(x)
# print(data)






# import tensorflow as tf
# data = tf.placeholder(tf.float32,[1, 5])
# # with tf.Session() as sess:
# print(data)




import tensorflow as tf
# python pkl 文件读写
import pickle as pickle

train_data_np = pickle.load(open('Model/train_data.plk', 'rb'))
train_labels = pickle.load(open('Model/train_labels.plk', 'rb'))

eval_data_np = pickle.load(open('Model/eval_data.plk', 'rb'))
eval_labels = pickle.load(open('Model/eval_labels.plk', 'rb'))

with tf.Session() as sess:
train_data = tf.convert_to_tensor(train_data_np)
eval_data = tf.convert_to_tensor(eval_data_np)

print(train_data.eval())
# print(train_labels)
print(eval_data.eval())
# print(eval_labels)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-

import json
'''
Json模块提供了四个功能:dumps、dump、loads、load
- dumps把python数据类型转换成字符串 json_str = json.dumps(test_dict)
- dump把数据类型转换成字符串并存储在文件中 json.dump(new_dict,file)
- loads把字符串转换成数据类型 new_dict = json.loads(json_str)
- load把文件打开从字符串转换成数据类型 load_dict = json.load(load_file)
'''

def myJsonDump(filePath,pyDict):
'''dump把数据类型转换成字符串并存储在文件中'''
with open(filePath,"w") as fileJson:
json.dump(pyDict,fileJson)
print("加载入文件完成...")

def myJsonLoad(filePath):
'''把文件打开从字符串转换成数据类型'''
with open(filePath,'r') as load_file:
load_dict = json.load(load_file)
return load_dict
'''
写入json文件示例:
test_dict = {'bigberg': [7600, {1: [['iPhone', 6300], ['Bike', 800], ['shirt', 300]]}]}

with open("../config/record.json",'r') as load_f:
load_dict = json.load(load_f)
print(load_dict)


load_dict['smallberg'] = [8200,{1:[['Python',81],['shirt',300]]}]
print(load_dict)

with open("../config/record.json","w") as dump_f:
json.dump(load_dict,dump_f)

'''


Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

import json
'''
Json模块提供了四个功能:dumps、dump、loads、load
- dumps把python数据类型转换成字符串 json_str = json.dumps(test_dict)
- dump把数据类型转换成字符串并存储在文件中
- loads把字符串转换成数据类型
- load把文件打开从字符串转换成数据类型
'''

''' dumps:将python中的 字典 转换为 字符串 '''
test_dict = {'bigberg': [7600, {1: [['iPhone', 6300], ['Bike', 800], ['shirt', 300]]}]}
print(test_dict)
print(type(test_dict))
#dumps 将数据转换成字符串
json_str = json.dumps(test_dict)
print(json_str)
print(type(json_str))

''' loads: 将 字符串 转换为 字典 '''
new_dict = json.loads(json_str)
print(new_dict)
print(type(new_dict))

''' dump: 将数据写入json文件中 '''
with open("../config/record.json","w") as f:
json.dump(new_dict,f)
print("加载入文件完成...")

''' load:把文件打开,并把字符串变换为数据类型 '''
# with open("../config/record.json",'r') as load_f:
with open("record.json",'r') as load_f:
load_dict = json.load(load_f)
print(load_dict)


load_dict['smallberg'] = [8200,{1:[['Python',81],['shirt',300]]}]
print(load_dict)

# with open("../config/record.json","w") as dump_f:
with open("record.json","w") as dump_f:
json.dump(load_dict,dump_f)


Loading