Code Monkey home page Code Monkey logo

spring-login2's Introduction

spring-login2

    public static void main(String[] args) {
        try {
            for (int i = 0; i < 10000; i++) {
                IVerifyCodeGen iVerifyCodeGen = new SimpleCharVerifyCodeGenImpl();
                VerifyCode verifyCode = null;
                verifyCode = iVerifyCodeGen.generate(80, 28);
                String code = verifyCode.getCode();
                byte[] img = verifyCode.getImgBytes();
                int len;
                File sf=new File("D:\\Workspace\\learning\\java\\jacoco-multiple-modules-demo-master\\captcha\\captcha2\\outputimg");
                if(!sf.exists()){
                    sf.mkdirs();
                }
                OutputStream os = new FileOutputStream(sf.getPath()+"\\"+code+".jpeg");
                os.write(img);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
import time
import os

# 导入包
import muggle_ocr

# ModelType.Captcha 可识别4-6位验证码
sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha)
path = "/root/test" #文件夹目录
files= os.listdir(path) #得到文件夹下的所有文件名称
totle_example=0
success_example=0
error_example=0
error_set=[]
for file in files: #遍历文件夹
    (_, all_filename) = os.path.split(file)
    (filename, ext) = all_filename.split(".")
    if ext == "jpeg":
       totle_example += 1
       target = filename.lower()
       with open(os.path.join(path, file), "rb") as f:
           b = f.read()
           st = time.time()
           predict = sdk.predict(image_bytes=b)
       if target == predict:
           success_example += 1
       else:
           error_example += 1
           error_set.append([target, predict])
print("totle:%d, success:%d, err:%d" % (totle_example, success_example, error_example))
print(error_set)

======================

使用tensorflow进行联邦学习

下载tensorflow_federated模块,此处使用较稳定的0.13.1版本,可根据实际情况选择版本

pip3 install --upgrade tensorflow_federated==0.13.1 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

引入所需模块

import tensorflow as tf
import tensorflow_federated as tff

下载手写体数字识别数据集

source, _ = tff.simulation.datasets.emnist.load_data()
def client_data(n):
  return source.create_tf_dataset_for_client(source.client_ids[n]).map(
      lambda e: (tf.reshape(e['pixels'], [-1]), e['label'])
  ).repeat(10).batch(20)
  # Pick a subset of client devices to participate in training.
train_data = [client_data(n) for n in range(3)]
# Grab a single batch of data so that TFF knows what data looks like.
sample_batch = tf.nest.map_structure(
    lambda x: x.numpy(), iter(train_data[0]).next())

定义模型

# Wrap a Keras model for use with TFF.
def model_fn():
  model = tf.keras.models.Sequential([
      tf.keras.layers.Dense(10, tf.nn.softmax, input_shape=(784,),
                            kernel_initializer='zeros')
  ])
  return tff.learning.from_keras_model(
      model,
      dummy_batch=sample_batch,
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])

训练模型

# Simulate a few rounds of training with the selected client devices.
trainer = tff.learning.build_federated_averaging_process(
  model_fn,
  client_optimizer_fn=lambda: tf.keras.optimizers.SGD(0.1))
state = trainer.initialize()
for _ in range(20):
  state, metrics = trainer.next(state, train_data)
  print (metrics.loss)

训练结果

Instructions for updating:
If using Keras pass *_constraint arguments to layers.
11.67063
11.65545
11.121943
10.477433
8.830841
7.7931805
7.192688
5.1021852
5.1880836
3.3151658
3.3807354
3.3242536
2.30087
1.7061236
1.5317304
1.1874161
0.7962298
0.94748044
0.7774023
0.6510306

spring-login2's People

Contributors

zivenyang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.