[LiteOS] usb-otg与stlink接口详解

每当接板子的时候都会有一个困惑,需不需要买下载器,抑或直接插到板子上就可以。

IoT Board 开发板

这块板子为例。右边有两个口,分别对应usb-otg与stlink。

从华为liteos doc是这么说的

USB OTG的工作原理
  OTG补充规范对USB 2.0的最重要的扩展是其更具节能性的电源管理和允许设备以主机和外设两种形式工作。OTG有两种设备类型:两用OTG设备(Dualrole device)和外设式OTG设备(Peripheralonly OTG device) 。两用OTG设备完全符合USB 2.0规范,同时,他还要提供有限的主机能力和一个MiniAB插座、支持主机流通协议(Host Negotiatio n Protocol, HNP),并和外设式OTG设备一样支持事务请求协议(Session Request Protocol, SRP)。当作为主机工作时,两用OTG设备可在总线上提供8 mA的电流,而以往标准主机则需要 提供100~500 mA的电流。
  2个两用OTG设备连接在一起时可交替以主机和从机的方式工作,这个特点兼容了现有USB 规范主机/外设的结构模型。OTG主机负责初始化数据通信的任务,比如:总线复位、获取USB 各种描述符和配置设备。这些配置完成后,2个OTG设备便可以分别以主机和从机方式传输信息,2个设备主从角色交换的过程由主机传输协议(HNP)定义。

1.1主机(Adevice)和从机(Bdevice)的初始功能
  设备的初始功能是通过定义连接器来实现的。OTG定义了一个叫做MiniAB的袖珍插孔,他能直接接入MiniA或者MiniB插口,MiniAB有一个ID引脚 上拉至电源端,MiniA插头有一个与地连接好的ID(R<10 Ω),Mini B插头有一个与地连接的开路ID引脚(R>100 kΩ)。当2个OTG设备连接到一起的时候 ,MiniA插头边的ID引脚会注入一个“0”状态,MiniB插头边的ID引脚为 “1”,ID为0的OTG设备默认为主机(Adevice),ID为1的OTG设备默认为从机(B device)。图1对上述内容进行了图解。

1.2对话请求协议SRP(Session Request Protocol)
  这个协议允许Adevice(可以是电池供电)在总线未使用时通过切断Vbus来节省电源消耗,也为Bdevice启动总线活动提供了一种方法。任何一个Adevice, 包括PC或便携式电脑,都可以响应SRP;任何一个Bdevice,包括一个标准USB外设, 都可以启动SRP;要求一个双重功能设备既能启动SRP,又能响应SRP。
1.3主机流通协议HNP(Host Negotiation Protocol)
  HNP是一种用来实现Adevice和Bdevice主机/从机转换的协议(实际上是电缆的反转)。主/从机功能交换的结果表现在下列过程中:
  (1)利用上拉电阻来发送信号给从机。
  (2)Adevice可在Bdevice上设置“HNP Enable”特性。
  (3)Bdevice断开上拉。
  (4)ADevice与上拉电阻相连,表明Adevice从属于从机。
  (5)Adevice给Vbus供电。
  (6)Bdevice检测Adevice的上拉。
  (7)复位/列举/使用Adevice。
1.4驱动程序
  与PC主机不同,便携式设备没有便捷的方式和足够的空间装载新的驱动程序。因此,OTG 规范要求每个两用OTG设备有一个支持的外设式OTG目标设备的列表,列表中包括设备的类型和制造商等信息。
  与PC机不同,OTG两用设备的驱动程序栈由USB主机栈和USB设备栈构成以满足两种工作方式的需要。OTG驱动程序通过连接器的不同或者是否有NHP交换设备的工作方式来决定使用USB主机栈还是USB设备栈。
  当OTG两用设备以主机方式工作时,USB主机栈工作。其中的主机控制器驱动程序负责USB 主机栈与硬件端点的数据交换,USB驱动程序枚举并保存设备的信息,目标外设主机类驱动程序支持目标设备列表里的设备。主机类驱动程序由芯片制造商提供,同时,OTG提供通用的主机类驱动程序(可以修改以用于非通用设备)。
  当OTG两用设备以从机方式工作时,USB设备栈工作。其中的设备控制器驱动程序负责USB 设备栈与硬件端点的数据交换,USB协议层负责处理USB协议规范,设备类驱动程序的功能取决于该两用设备的功能(如数码照相机、存储设备、打印机等)。
  OTG驱动程序负责处理两用OTG设备的工作方式转换,同时,他还可以返回其结果(如设备是否支持HNP)并处理总线错误。应用层程序通过OTG驱动程序开始或者结束一个传输事务, 通过USB主机栈或设备栈与硬件层交换数据。
1.5数据流模型
  OTG主机和设备被划分为功能层、USB设备层和USB接口层3个不同层次,如图2所示。

  USB接口层为OTG主机和OTG设备提供物理连接,USB系统软件使用主机控制器来管理主机与 USB设备的数据传输。USB系统软件相对于主机控制器而言,处理的是以客户角度观察的数据传输及客户与设备的交互。USB设备层为USB主机系统软件提供一个可用的逻辑设备。主机通过与之功能匹配的客户软件实现其各种功能。

USB OTG接口中有5条线:
2条用来传送数据(D+ 、D-);
1条是电源线(VBUS);
1条则是接地线(GND)、
1条是ID线。

ID线—以用于识别不同的电缆端点,mini-A插头(即A外设)中的ID引脚接地,mini-B插头(即B外设)中的ID引脚浮空。当OTG设备检测到接地的ID引脚时,表示默认的是A设备(主机),而检测到ID引脚浮空的设备则认为是B设备(外设)。

在这里插入图片描述

为了增加OTG的两用功能,必须扩充收发器功能来使OTG设备既可作为主机使用,也可以作为外设使用。而要实现上述功能,就需要在图3所示电路中添加D+和D-端的15kΩ下拉电阻并为VBUS提供供电电源。此外,收发器还需要具备以下三个条件:

(1)可切换D+/D-线上的上拉和下拉电阻,以提供外设和主机功能。

(2)作为A设备时,需要具有VBUS监视和供电电路;作为B设备初始化SRP时,需要监视和触发VBUS。

在这里插入图片描述

(3)具有ID输入引脚。
  

作为两用OTG设备,ASIC、DSP或其它与收发器连接的电路必须具备充当外设和主机的功能,并应按照HNP协议转换其角色。

收发器所需添加的大多数电路用于VBUS引脚的管理。作为主机,它必须能够提供5V、输出电流可达8mA的电源。图3中的模拟开关用于配置收发器的各种功能。

在这里插入图片描述

ASIC和控制器还必须包含USB主机逻辑控制功能,包括发送SOF(帧启动)包、发送配置u36755输入u36755输出数据包,在USB 1 msec帧内确定传输进程、发送USB复位信号、提供USB电源管理等。

one ln problem in cuda10.1 /dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'

I faced a linking problem in cuda 10.0 is neither 10.1 nor 10, so we have to change it. Also cublas is not in the lib64 directory but in gnu directory in 10.1.

The turorial I follow is https://www.tensorflow.org/install/gpu

2019-08-12 06:57:41.705482: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:983] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
 2019-08-12 06:57:41.707082: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
 name: GeForce RTX 2070 with Max-Q Design major: 7 minor: 5 memoryClockRate(GHz): 1.185
 pciBusID: 0000:01:00.0
 2019-08-12 06:57:41.707394: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudart.so.10.0'; dlerror: libcudart.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.707637: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.707908: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.708132: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.708355: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.708580: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
 2019-08-12 06:57:41.708639: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
 2019-08-12 06:57:41.708665: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
 Skipping registering GPU devices…
 2019-08-12 06:57:41.709682: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
 2019-08-12 06:57:41.709692: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      
cd  /usr/local/cuda/lib64 && sudo ln lib*.so.10 lib*.so.10.0
cd /usr/lib/x86_64-linux-gnu && sudo ln libcublas.so.10 /usr/local/cuda/lib64/libcublas.so.10.0

again you can re start your python console and do tensorflow-gpu again

python -c import tensorflow as tf; print("GPU Available: ", tf.test.is_gpu_available())

上科大逻辑与形式化验证讲座3

Explicit-State Model Checking

  • X!y: add y as the last element of X
  • X!!y: add y as the first element of X
  • X?y: remove the first element of X as y
  • dfs from a reachable final state to check if a loop exists

Bitstate Hashing

Binary Decision Diagrams

  • (X0 && ! X1) || (X0 && X1) == X0
  • Boolean Function API
  • A BDD represents a Boolean function as an acyclic directed graph
    • Nonterminal vertices labeled by Boolean variables
    • Leaf vertices labeled with the values 1 and 0
  • Restrict(f,i,b):
    • R(x1 && x2, 1, True) == x2

BDD-based symbolic model checking

  • represent sets of state

  • represent transition relation
    • p’: p of next state
  • BddImage & BddPreImage

上科大逻辑与形式化验证讲座

时间逻辑与模型检查

克里普克结构
K=
符号逻辑

自然语言:
模棱两可的
悖论
代数逻辑

时间逻辑控制*

路径量词
A:对于此状态的每个无限路径(任意路径中的状态)
E:这个状态有一条无限的路径
时间运算符
xp:p保持在下一个状态
FP:P在未来的某些州持有
gp:p将来在所有州都持有
qup:fp,q在所有状态下保持,直到p保持。
时间逻辑控制

A、E和E、F、G、U必须成对站立
时态逻辑LTL(线性时态逻辑)

不e
只有一条路
算法挑战

对称性约简

飞行状态空间探索

部分降阶

假设保证推理

符号方法

BDD
抽象

模型检查的未来

合成(根据规范生成程序)
归纳、模型测量
人工智能????
建模软件

断言

转换:

启用条件:预测

转换:多重分配

A>B->(B,C):=(C,D)
执行:状态序列

LTL

☐盒子,永远,G
:钻石,最终,F
:下一个时间,x
有限词上的自动机

自动机
非确定性
确定性
正确性条件

我们希望找到一个模型满足规范的正确性条件。

模型语言:L(模型)
规范语言:L(规范)
我们需要:L(型号)L(规格)

程序执行符合规范的序列所有序列

Adversarial AI 学习日记


产生了一点没有用的垃圾。就是按照NTU学长的来一遍。

PS C:\Users\AERO> docker attach mynginx^C
PS C:\Users\AERO> docker attach dgl2019/icse2019-artifacts
Error: No such container: dgl2019/icse2019-artifacts 
PS C:\Users\AERO> docker attach docker.io/dgl2019/icse2019-artifacts 
Error: No such container: docker.io/dgl2019/icse2019-artifacts 
PS C:\Users\AERO> docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 
PS C:\Users\AERO> docker pull dgl2019/icse2019-artifacts 
Using default tag: latest 
latest: Pulling from dgl2019/icse2019-artifacts 
Digest: sha256:ddf6ceb380481b67485b18728f302958113569ea8571b9fcd78439724eeaaef8 
Status: Image is up to date for dgl2019/icse2019-artifacts:latest docker.io/dgl2019/icse2019-artifacts:latest 
PS C:\Users\AERO> docker ps 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 
PS C:\Users\AERO> docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE 
dgl2019/icse2019-artifacts latest a5a18674d9a4 6 months ago 6.43GB 
PS C:\Users\AERO> docker exec -it a5a18674d9a4 /bin/bash 
Error: No such container: a5a18674d9a4 
PS C:\Users\AERO> docker exec -it dgl2019/icse2019-artifacts /bin/bash 
Error: No such container: dgl2019/icse2019-artifacts
PS C:\Users\AERO> docker exec -it dgl2019 /bin/bash 
Error: No such container: dgl2019 
PS C:\Users\AERO> docker run -it dgl2019/icse2019-artifacts /bin/bash 
root@ef79040f7919:/# ls 
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@ef79040f7919:/# cd home/
root@ef79040f7919:/home# ls
icse2019
root@ef79040f7919:/home# cd icse2019/
root@ef79040f7919:/home/icse2019# ls
source
root@ef79040f7919:/home/icse2019# cd source/ root@ef79040f7919:/home/icse2019/source# ls
__init__.py attacks build-in-resource config detect lcr_auc model_mutation models scripts utils
root@ef79040f7919:/home/icse2019/source# cd config/
root@ef79040f7919:/home/icse2019/source/config# ls
logging.yaml
root@ef79040f7919:/home/icse2019/source/config# cd ..
root@ef79040f7919:/home/icse2019/source# cd model
bash: cd: model: No such file or directory
root@ef79040f7919:/home/icse2019/source# ls
__init__.py attacks build-in-resource config detect lcr_auc model_mutation models scripts utils
root@ef79040f7919:/home/icse2019/source# cd models
root@ef79040f7919:/home/icse2019/source/models# ls
__init__.py __init__.pyc ensemble_model.py ensemble_model.pyc googlenet.py googlenet.pyc lenet.py lenet.pyc
root@ef79040f7919:/home/icse2019/source/models# python lenet.py root@ef79040f7919:/home/icse2019/source/models# uname -r
4.9.184-linuxkit
root@ef79040f7919:/home/icse2019/source/models# uname -a Linux ef79040f7919 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 GNU/Linux
root@ef79040f7919:/home/icse2019/source/models# ls __init__.py __init__.pyc ensemble_model.py ensemble_model.pyc googlenet.py googlenet.pyc lenet.py lenet.pyc root@ef79040f7919:/home/icse2019/source/models# cd .. root@ef79040f7919:/home/icse2019/source# ls
__init__.py attacks build-in-resource config detect lcr_auc model_mutation models scripts utils
root@ef79040f7919:/home/icse2019/source# cd utils/ root@ef79040f7919:/home/icse2019/source/utils# ls
__init__.py data_manger.pyc logging_util.pyc model_trainer.py pytorch_extend.pyc
__init__.pyc imgnet12-valprep.sh model_manager.py model_trainer.pyc time_util.py
data_manger.py logging_util.py model_manager.pyc pytorch_extend.py time_util.pyc
root@ef79040f7919:/home/icse2019/source/utils# ls
__init__.py data_manger.pyc logging_util.pyc model_trainer.py pytorch_extend.pyc
__init__.pyc imgnet12-valprep.sh model_manager.py model_trainer.pyc time_util.py
data_manger.py logging_util.py model_manager.pyc pytorch_extend.py time_util.pyc
root@ef79040f7919:/home/icse2019/source/utils# cd .. root@ef79040f7919:/home/icse2019/source# cd scripts/ root@ef79040f7919:/home/icse2019/source/scripts# ./craftAdvSamples.sh
NOTE: Our experiments are only based on two datasets: mnist and cifar10,
but it is a piece of cake to extend to other datasets only providing a proper pytorch-style data loader tailored to himself datasets. Each attack manner has different parameters. All the parameters are organized in a list.The order of the parameters can be found in the REDME in this folder. To quickly yield adversarial samples, we provide a default setting for each attack manner.Do you want to perform an attack with the default settings?y/n y dataType ( [0] mnist; [1] cifar10):1 attackType:fgsm =======>Please Check Parameters<======= modelName: googlenet modelPath: ../build-in-resource/pretrained-model/googlenet.pkl dataType: 1 sourceDataPath: ../build-in-resource/dataset/cifar10/raw attackType: fgsm attackParameters: 0.03,true savePath: ../artifacts_eval/adv_samples/cifar10/fgsm device: -1 <======>Parameters=======> Press any key to start attack process CTRL+C break command bash... Crafting Adversarial Samples.... targeted model: Average loss: -11.4510, Accuracy: 9049/10000 (90.49%) ./craftAdvSamples.sh: line 129: 34 Killed python -u $exe_file --modelName ${modelName} --modelPath ${modelPath} --dataType ${dataType} --sourceDataPath ${sourceDataPath} --attackType ${attackType} --attackParameters ${attackParameters} --savePath ${savePath} --device ${device} DONE! root@ef79040f7919:/home/icse2019/source/scripts# nvidia-smi bash: nvidia-smi: command not found root@ef79040f7919:/home/icse2019/source/scripts# ks bash: ks: command not found root@ef79040f7919:/home/icse2019/source/scripts# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Thread(s) per core: 2 Core(s) per socket: 1 Socket(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Stepping: 10 CPU MHz: 2362.464 BogoMIPS: 4724.92 Hypervisor vendor: Microsoft Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 12288K root@ef79040f7919:/home/icse2019/source/scripts# lspci bash: lspci: command not found root@ef79040f7919:/home/icse2019/source/scripts# dmseg bash: dmseg: command not found root@ef79040f7919:/home/icse2019/source/scripts# dmesg dmesg: read kernel buffer failed: Operation not permitted root@ef79040f7919:/home/icse2019/source/scripts# sudo dmesg bash: sudo: command not found root@ef79040f7919:/home/icse2019/source/scripts# ^Cdo dmesg root@ef79040f7919:/home/icse2019/source/scripts# ./advSampelsVerify.sh 0 ../artifacts_eval/adv_samples/mnist/fgsm/2019-01-13_03:48:45 -1 1 Traceback (most recent call last): File "../attacks/attack_util.py", line 369, in test_adv_samples() File "../attacks/attack_util.py", line 318, in test_adv_samples ]), show_file_name=True, img_mode=img_mode, max_size=10000) File "../utils/data_manger.py", line 240, in __init__ all_files = np.array([img_file for img_file in os.listdir(root)]) OSError: [Errno 2] No such file or directory: '../artifacts_eval/adv_samples/mnist/fgsm/2019-01-13_03:48:45' root@ef79040f7919:/home/icse2019/source/scripts# ls advSampelsVerify.sh craftAdvSamples.sh default_cifar10_auc_analysis.sh default_mnist_auc_analysis.sh detect.sh lcr_acu_analysis.sh modelMuated.sh root@ef79040f7919:/home/icse2019/source/scripts# ./advSampelsVerify.sh 0 ../a artifacts_eval/ attacks/ root@ef79040f7919:/home/icse2019/source/scripts# ./advSampelsVerify.sh 0 ../artifacts_eval/adv_samples/cifar10/fgsm/2019-08-07_00\:04\:11/ -1 1 Total:0,Success:0 root@ef79040f7919:/home/icse2019/source/scripts# ./craftAdvSamples.sh NOTE: Our experiments are only based on two datasets: mnist and cifar10, but it is a piece of cake to extend to other datasets only providing a proper pytorch-style data loader tailored to himself datasets. Each attack manner has different parameters. All the parameters are organized in a list.The order of the parameters can be found in the REDME in this folder. To quickly yield adversarial samples, we provide a default setting for each attack manner.Do you want to perform
an attack with the default settings?y/n
y
dataType ( [0] mnist; [1] cifar10):0
attackType:fgsm
=======>Please Check Parameters<======= modelName: lenet modelPath: ../build-in-resource/pretrained-model/lenet.pkl dataType: 0 sourceDataPath: ../build-in-resource/dataset/mnist/raw attackType: fgsm attackParameters: 0.35,true savePath: ../artifacts_eval/adv_samples/mnist/fgsm device: -1 <======>Parameters=======>
Press any key to start attack process
CTRL+C break command bash...
Crafting Adversarial Samples....

targeted model: Average loss: -12.9422, Accuracy: 9829/10000 (98.29%)
y
Eps=0.35: Average loss: -7.5184, Accuracy: 7775/9829 (79.10%)
successful samples 2054
Done!
icse19-eval-attack-fgsm: rename 125, remove 40,success 1889
Adversarial samples are saved in ../artifacts_eval/adv_samples/mnist/fgsm/2019-08-07_00:58:21
DONE!
root@ef79040f7919:/home/icse2019/source/scripts# /modelMuated.sh
bash: /modelMuated.sh: No such file or directory
root@ef79040f7919:/home/icse2019/source/scripts# 。/modelMuated.sh bash: 。/modelMuated.sh: No such file or directory
root@ef79040f7919:/home/icse2019/source/scripts# ./modelMuated.sh NOTE: Our experiments are only based on two datasets: mnist and cifar10,

but it is a piece of cake to extend to other datasets only providing a

proper pytorch-style data loader tailored to himself datasets.
To quickly verify the mutation process, we provide a group of default parameters,do you want to quickly start the
program?y/n
y
=======>Parameters<======= modelName: lenet modelPath: ../build-in-resource/pretrained-model/lenet.pkl accRation: 0.9 dataType: 0 numMModels: 10 mutatedRation: 0.001 opType: GF savePath: ../artifacts_eval/modelMuation/ device: -1 <======>Parameters=======>
Press any key to start mutation process
CTRL+C break command bash...
2019-08-07 00:59:08,632 - INFO - data type:mnist
2019-08-07 00:59:08,637 - INFO - >>>>>>>>>>>>Start-new-experiment>>>>>>>>>>>>>>>>
2019-08-07 00:59:10,078 - INFO - orginal model acc=0.9829
2019-08-07 00:59:10,079 - INFO - acc_threshold:88.0%
2019-08-07 00:59:10,079 - INFO - seed_md_name:lenet,op_type:GF,ration:0.001,acc_tolerant:0.9,num_mutated:10
2019-08-07 00:59:10,091 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:12,375 - INFO - Mutated model: accurate 0.9818
2019-08-07 00:59:12,379 - INFO - Progress:1/10
2019-08-07 00:59:12,388 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:13,678 - INFO - Mutated model: accurate 0.9832
2019-08-07 00:59:13,682 - INFO - Progress:2/10
2019-08-07 00:59:13,691 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:14,958 - INFO - Mutated model: accurate 0.9823
2019-08-07 00:59:14,960 - INFO - Progress:3/10
2019-08-07 00:59:14,971 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:16,271 - INFO - Mutated model: accurate 0.9827
2019-08-07 00:59:16,274 - INFO - Progress:4/10
2019-08-07 00:59:16,283 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:17,582 - INFO - Mutated model: accurate 0.9829
2019-08-07 00:59:17,586 - INFO - Progress:5/10
2019-08-07 00:59:17,595 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:18,764 - INFO - Mutated model: accurate 0.9829
2019-08-07 00:59:18,767 - INFO - Progress:6/10
2019-08-07 00:59:18,777 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:19,921 - INFO - Mutated model: accurate 0.982
2019-08-07 00:59:19,923 - INFO - Progress:7/10
2019-08-07 00:59:19,932 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:21,072 - INFO - Mutated model: accurate 0.9823
2019-08-07 00:59:21,075 - INFO - Progress:8/10
2019-08-07 00:59:21,086 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:22,262 - INFO - Mutated model: accurate 0.983
2019-08-07 00:59:22,264 - INFO - Progress:9/10
2019-08-07 00:59:22,274 - INFO - 61/61706 weights to be fuzzed
2019-08-07 00:59:23,442 - INFO - Mutated model: accurate 0.9824
2019-08-07 00:59:23,444 - INFO - Progress:10/10
The mutated models are stored in ../artifacts_eval/modelMuation/2019-08-07_00:59:08/gf0.001/lenet
root@ef79040f7919:/home/icse2019/source/scripts# ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy^C
root@ef79040f7919:/home/icse2019/source/scripts# ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy
bash: ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy: Permission denied
root@ef79040f7919:/home/icse2019/source/scripts# sudo ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy
bash: sudo: command not found
root@ef79040f7919:/home/icse2019/source/scripts# chmod 777 ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy
root@ef79040f7919:/home/icse2019/source/scripts# ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy bash: ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy: cannot execute binary file: Exec format error
root@ef79040f7919:/home/icse2019/source/scripts# cat ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy
�NUMPY v {'descr': '<f8', 'fortran_order':="" false,="" 'shape':="" (1000,),="" }="" j�t�x?�i="" +��?�i="" +��?="" ���mb�?="" ���mbp?="" ���mb�?��&��?="" �="" ���mb`?="" ���mb�?��~j�t�?="" ���mbp?��g�z�?="" j�t�x?="" j�t="" ��?="" ���mbp?@�o��n�?h��|?5�?��g�z�?="" v-��?��g�z�?="" ���mb`?8�o��n�?="" ��mb`?="" @�o��n�?="" ���mbp?8��v���?="" �?="" ��="" j�t�x?�������?��g�z�?="" ���mb`?��g�z�?="" ���mbj�t�x?="" j�t��?="" ����mb�?l7�a`��?="" ���x�&�?="" ���s="" �?@�o��n�?="" ��ʡe��?="" ���mb�?����s�?="" ���mb`?�������?="" j�t�x���mb�?="" ��&��?="" ���mb�?@�o��n�?="" q����?="" @��v���?="" b`?="" ���mb`?����mb�?��&��?="" ���mb`?��&��?="" ���mb`?���(\="" bp?="" ���mb`?�i="" �l�����?="" j�&1�?="" j�t�x?��&��?="" ���mb`?�zd�?�ʡe���?="" ����mb`?="" 8��v���?="" ���mb`?��~j�t�?="" j�t�x?x9��v��?`��"���?�x�&��?="" ���mb`?��q��?��&��?="" ���mb�?��g�z�?="" �t��?="" j�t��?�l�����?="" ���mbp?�l�����?="" ?="" ���q��?="" ��b�?���s㥫?�i="" ���mbp?"��~j��?="" j�t��?��&��?="" ���mbp?��&��?="" jp?="" ��g�z�?="" `9��v��?="" ���mb�?�l�����?x9��v��?="" ���mbp���mb`?="" ���mb�?��g�z�?@�o��n�?="" j�t�x?zd;�o��?="" �"��~j�?="" j�tb`?="" ���mb�?�i="" +��?@��v���?="" ���mb�?��g�z�?�v��="" ���mb�?~j�t��?="" ���mb`?���s��?8��v���?="" +��?��g�z�?�q�����mb`?="" ���mb`?�v-�?="" ���mbp?8�o��n�b`?l7�a`��?="" ��c�l��?="" j�t��?�a�g�z�?���q��?="" j�t�x?�~j�t��?��&��?="" j�t�x?="" ��g�z�?�v��="" ���mb�?أp="��?" �i="" ���mbp?ȡe����?="" ��&��?@��v���?="" v-��?@��v���?="" j�t�x?�z�g��?="" ���mbp?��~j�t�?="" ���mb`?@�o��n�?="" ���mbp?䥛�="" ��g="" �q����?="" v-��?="" j�t�x?@��v���?="" ��g�z�b`?="" ���mb`?��="" �rh�?="" j�t��?��&��?��ʡe��?="" ��p?="" �����k�?="" ���mb�?="" @��v�="" -��?="" ���mb`?h�t��?��&��?�i="" +��?��&��?�������?��g�z�?="" mb`?="" 8�o��n�?="" ���mb`?̡e����?="" +��?��g�z�?="" ���mbp?@�o��n�?="" ��g�z�?�i="" `?��&��?��&��?="" `d;�o��?="" ���mbp?&�z�?="" @`��"��?="" +��?�"��~j�?="" j�t��?@�o��n�?mb`?="" ����mb�?�"��~j�?="" 433333�?="" ���mb`?�|?5^��?��&��?="" @�o��n�?�&��?="" ���m���mb`?�v��="" ���mb`?�~j�t��?="" l7�a`��?="" ���mbp?���x�&�?="" b`?�i="" +��?���q��?��c�l�?="" �������?����mb�?="" ���mb`?root@ef79040f7919:="" home="" icse2019="" source="" scripts#="" root@ef79040f7919:="" .="" lcr_acu_analysis.sh="" note:="" our="" experiments="" are="" only="" based="" on="" two="" datasets:="" mnist="" and="" cifar10,="" but="" it="" is="" a="" piece="" of="" cake="" to="" extend="" other="" datasets="" providing="" proper="" pytorch-style="" data="" loader="" tailored="" himself="" datasets.="" quickly="" label="" change="" rate="" auc="" statistics="" ,="" we="" provide="" group="" default="" parameters,do="" you="" want="" start="" the="" program?y="" n="" y="" please="" lcr="" result="" normal="" samples="" for="" computinglease="" test.="" do="" have="" results="" samples?(y="" n)y="" path="" normal's="" list:..="" build-in-resource="" nr-lcr="" mnsit="" lenet="" gf="" 5e-2p="" nrlcr.npy="======">Please Check Parameters<======= dataType: mnist device: -1 testType: adv useTrainData: False batchModelSize: 2 maxModelsUsed: 10 mutatedModelsPath: ../build-in-resource/mutated_models/mnist/lenet/gf/5e-2p/ testSamplesPath: ../build-in-resource/dataset/mnist/adversarial/jsma/ seedModelName: lenet test_result_folder: ../lcr_auc-testing-results/mnist/lenet/gf/5e-2p/jsma/ The test will be divided into 5 batches The logs will be saved in: ../lcr_auc-testing-results/mnist/lenet/gf/5e-2p/jsma/-2019-08-07-01 is_adv: True nrLcrPath: ../build-in-resource/nr-lcr/mnsit/lenet/gf/5e-2p/nrLCR.npy <======>Parameters=======>
Press any key to start mutation process
CTRL+C break command bash...
batch:1
model_start_no:1
batch:2
model_start_no:3
batch:3
model_start_no:5
batch:4
model_start_no:7
batch:5
model_start_no:9
Testing Done!
>>>>>>>>>>>seed data:mnist,mutated_models:../build-in-resource/mutated_models/mnist/lenet/gf/5e-2p/<<<<<<<<<< >>>>>>>>>>>mnist<<<<<<<<<<<<<< Total Samples Used:1000,auc:0.9871,avg_lcr:0.5032,std:0.1693,confidence(95%):0.0105,confidence(98%):0.0125,confidence(99%):0.0138 root@ef79040f7919:/home/icse2019/source/scripts# ./detect.sh NOTE: Our experiments are only based on two datasets: mnist and cifar10, but it is a piece of cake to extend to other datasets only providing a proper pytorch-style data loader tailored to himself datasets. To quickly perform adversarial detection, we provide a group of default parameters,do you want to quickly start the program?y/n y ./detect.sh: line 44: $'\n\nthrehold threhold\nextendScale extendScale\nrelaxScale relaxScale\nmutatedModelsPath mutatedModelsPath\nalpha alpha\nbeta beta\ntestSamplesPath testSamplesPath\ndataType dataType\ntestType testType\nseedModelPath seedModelPath\n\n': command not found =======>Please Check Parameters<======= threhold: 0.0441 extendScale: 1.0 relaxScale: 0.1 mutatedModelsPath: ../build-in-resource/mutated_models/mnist/lenet/nai/5e-2p/ alpha: 0.05 beta: 0.05 testSamplesPath: ../build-in-resource/dataset/mnist/adversarial/jsma/ dataType: 0 testType: adv seedModelPath: ../build-in-resource/pretrained-model/lenet.pkl mutatedModelsPath: ../build-in-resource/mutated_models/mnist/lenet/nai/5e-2p/ device: -1 <======>Parameters=======>
Press any key to start mutation process
CTRL+C break command bash...</f8',>

Processed:100.00 %adverage accuracy:0.998, avgerage mutated used:35.538
root@ef79040f7919:/home/icse2019/source/scripts

中午去就是看paper,看到自闭,看完做自己的事情了,没管其他。
可笑的是我只看了5篇就看不下去了。
和学长聊天也算知道了现在的学术圈现状。
简单的东西划水就比较多。
加油吧

有了自己的第一个oj


基本上都是用别人的轮子https://docs.onlinejudge.me/#/onlinejudge/guide/test_case
总算是比我们张龙文小朋友搭的oj.geekpie.club好用,不过他那个用gauth和django就得学一会儿了。
废话不多说,上代码https://www.zhihu.com/question/23067497
只能说别人的太过牛逼

离散所导出来的大整数存储和运算问题

python可以自动解决这个问题,但到了c++下要存128以上就要gmp mp boost 这种库,实现逻辑也很简单,速度会比python快很多。

这里放一个java版一个大数乘法的案例

public static Integer[] bigNumberMultiply(int[] arr1, int[] arr2){
   ArrayList result = new ArrayList<>();  //中间求和的结果 
   //arr2 逐位与arr1相乘
   for(int i = arr2.length - 1; i >= 0; i--){
     int carry = 0;
     ArrayList singleList = new ArrayList<>(); //arr2 逐位单次乘法的结果
     for(int j = arr1.length - 1; j >= 0; j--){
        int r = arr2[i] * arr1[j] + carry;
        int digit = r % 10;
        carry = r / 10;singleList.add(digit);
     } 
     if(carry != 0){
         singleList.add(carry); 
     } 
     int resultCarry = 0, count = 0; 
     int k = 0; 
     int l = 0; 
     int offset = arr2.length - 1 - i;       //加法的偏移位      
     ArrayList<Integer> middleResult = new ArrayList<>(); //arr2每位乘法的结果与上一轮的求和结果相加,从右向左做加法并进位 
     while (k < singleList.size() || l < result.size()) {
         int kv = 0, lv = 0;     
         if (k < singleList.size() && count >= offset) {
            kv = singleList.get(k++);     
         }
         if (l < result.size()) {
            lv = result.get(l++);     
         }     
         int sum = resultCarry + kv + lv;
         middleResult.add(sum % 10);     //相加结果从右向左(高位到低位)暂时存储,最后需要逆向输出     
         resultCarry = sum / 10;
         count++; 
     }
     if(resultCarry != 0){
         middleResult.add(resultCarry); 
     } 
     result.clear(); 
     result = middleResult;
  } 
  Collections.reverse(result);    //逆向输出结果
  return result.toArray(new Integer[result.size()]);
}

快速幂算法其实也用到了其中的想法。只是存储在数组,分区块乘法,再数组存储,这是高精度的方法。而快速幂是分开运算由数学公式保证正确性。

快速幂的复杂度是O(logn)大数存储和乘法是O(n^2)

可是这点数字在ipadpro 下来运行还是秒出的。

《设计模式》(C++)总结

之前在CS100上了解到了工厂模式和Adaptor 模式

Factory Method

class Shape{
public:
    static Shape * make_shape(int choice);
    virtual void print() = 0; //纯虚函数
};
class Circle:public Shape{/*..*/ };
class Square:public Shape{/*..*/ };
class Rectangle:public Shape{/*..*/ };

Shape * Shape::make_shape(int choice) {
    switch (choice) {
        case 1:
            return new Circle();
        case 2:
            return  new Square();
        case 3:
            return new Rectangle();
    }
}

后来写Compiler的时候觉得Factory Method可以用于传函数指针的代码生成器。

/*** Factory methods */
static string instConst(string (*inst)(const Reg &target, const Reg &op1, const Value &op2, string comment),
                            const Reg &target, const Reg &op1, const Constant &op2);
static string instConst(string (*inst)(const Reg &target, const Reg &op1, const Reg &op2, string comment),
                            const Reg &target, const Reg &op1, const Constant &op2);
static string instConst(string (*inst)(const Reg &target, const Reg &op1, int imm, string comment),
                            const Reg &target, const Reg &op1, const Constant &op2);
static string instConst(string (*inst)(const Reg &op1, const Value &op2, string comment), const Reg &op1,
                            const Constant &op2);

Adaptier Pattern

class LegacyRectangle{
public:
    LegacyRectangle(float x1,float y1,float  x2, float y2){
        m_x1=x1; m_y1=y1; m_x2=x2; m_y2=y2;
    }
    float area(){
        return (m_x2-m_x1)*(m_y2-m_y1);
    }
private:
    float m_x1;
    float m_x2;
    float m_y1;
    float m_y2;
};
class Rectangle{
public:
    virtual float areaSqInch(); //unit:square-inch
};
class RectangleAdapter:public Rectangle,private LegacyRectangle{
public:
    RectangleAdapter(float x,float y,float w,float h): LegacyRectangle(x/39.27f,y/39.37f,(x+w)/39.37f,(y+h)/39.37f){}
    virtual float areaSqInch(){
        float areaSqM = area();
        return areaSqM * 1550.0f;
    }
};

用一个双向继承关系来完成Adaptor的功能。

这是在B站上设计模式那本书的总结

非常魔性的"静态"美