17 篇文章带有标签 “tutorial”

命令find

查找文件

-name 或 -iname(大小写不敏感)

find . -name "*.pyc"

-m(最近多长时间修改)

min, 分钟
time, 哪天 0(24小时) 1(24-48小时) 2(48-72小时)
  • 显示 /var/log 目录下最近 10分钟内修改的文件
$ find /var/log -mmin -10
/var/log/messages
  • 以详细信息显示 /var/log 目录下最近 24小时内修改的文件
$ find /var/log -mtime 0 -ls
 33575669      4 drwxr-xr-x  15  root     root         4096 7月 29 06:33 /var/log
 34131780    164 -rw-------   1  root     root       166061 7月 29 10:20 /var/log/messages
  • 显示 /var/log 目录下最近 [0 - 24小时] 修改的文件
find /var/log -mtime -1
  • 显示 /var/log 目录下最近 [24 - 48小时] 修改的文件
find /var/log -mtime 1
  • 显示 /var/log 目录下最近 [48 - ] 修改的文件
find /var/log -mtime +1

-size(文件大小) 显示当前目录下超过 40M的文件 $ find .

命令grep

搜索文件内容

  • 搜索一个文件
grep 'text' hello.txt
  • 忽略字母大小写(-i)
grep -i 'text' hello.txt
  • 搜索多个文件
grep 'text' hello.txt hi.txt
  • 搜索当前目录下所有文件
grep 'text' *
  • 搜索当前目录(包含子目录 -R)下所有文件
grep -R 'text' *

匹配搜索

  • 搜索 pip 配置文件的路径 -R(遍历) -n(行号) -H(文件名)
grep "index-url" ~/.config -RnH
/home/lnsoft/.config/pip/pip.conf:2:index-url = https://mirrors.aliyun.com/pypi/simple/
  • 搜索 pip 配置文件的路径(增加过滤)
find ~ -name pip* | xargs -i grep "index-url" {} --color -nH
/home/lnsoft/.config/pip/pip.conf:2:index-url = https://mirrors.aliyun.com/pypi/simple/
  • 只匹配字符串,不使用正则表达式。
find . | grep -F .run

图像格式转换、尺寸调整

查看图像信息

$ file test.jpg
test.jpg: JPEG image data, JFIF standard 1.02, resolution (DPI), density 96x96, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=7, orientation=upper-left, xresolution=98, yresolution=106, resolutionunit=2, software=Adobe Photoshop CS Windows, datetime=2013:03:18 11:45:34], baseline, precision 8, 750x499, frames 3

ImageMagick

ImageMagick是一个用于查看、编辑位图文件以及进行图像格式转换的开放源代码软件套装。它可以读取、编辑超过100种图像格式。

安装

  • Ubuntu
sudo apt-get install imagemagick
  • macOS
brew install imagemagick

格式转换

convert test.jpg test.png

灰度

convert -colorspace gray input_file output_file

命令wget

下载多个文件

  • 空格分割
wget https://upload.wikimedia.org/wikipedia/commons/1/13/Intel_CPU_Core_i7_6700K_Skylake_perspective.jpg https://images-na.ssl-images-amazon.com/images/I/51iVSqLIBWL._AC_.jpg
  • 来自文件(-i)
wget -i urls.txt

后台下载(-b)

wget -i urls.txt -b

指定输出目录

wget -i urls.txt -P output

断点续传(-c --continue)

wget -c https://github.com/goharbor/harbor/releases/download/v2.1.3/harbor-offline-installer-v2.1.3.tgz

命令ls

可读的方式显示文件大小

# -h, --human-readable with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
ls -lh
ll -h

显示目录的所有子目录的内容

# -R, --recursive list subdirectories recursively
ls -lR
ll -R

按时间进行排序

按时间降序显示当前目录

# -l use a long listing format; -t sort by modification time, newest first
ls -lt
ll -t

按时间升序显示当前目录

# -r --reverse reverse order while sorting
ls -lrt
ll -rt

按大小进行排序

按大小降序显示当前目录

# -S sort by file size, largest first
ls -lS
ll -S

按大小升序显示当前目录

ls -lrS
ll -rS

统计目录下文件数量

统计当前目录下的文件数量

ls -l | grep "^-" | wc -l

统计当前目录下的目录数量

ls -l | grep "^d" | wc -l

统计当前目录下(包含子目录)的文件数量 ls -lR | grep

Python文件、目录、路径操作

导入包

>>> import os
>>> import shutil

文件

拷贝文件

目录路径可以是目录名

>>> shutil.copy('/home/python/main.py', '/home/python/main.py.bak')
>>> shutil.copy('/home/python/main.py', '/home/python/bak/')

创建文件

  • 方法1
open(filename, 'w').close()
  • 方法2
def touch(path):
    with open(path, 'a'):
        os.utime(path, None)
  • 方法3

OS X需要root特权

os.mknod(filename)

修改文件名

>>> os.rename('filename', 'new_filename')

删除文件

>>> os.remove('/home/python/main.py')

目录

拷贝目录树 >>> shutil.

使用Detectron在自定义数据集上训练MaskRCNN

拉取镜像 Detectron

sudo docker pull gouchicao/detectron:latest

创建工程(COCO格式)

└── helmet          工程目录
    ├── images        样本图片目录
    ├── helmet_train.json 训练的样本标注信息
    ├── helmet_val.json  验证的样本标注信息
    ├── test               测试图片目录
    ├── predict            预测图片目录
    ├── model        模型目录
    └── e2e_mask_rcnn_R-101-FPN_2x.yaml  网络配置文件

运行容器 Detectron,挂载工程目录。

sudo docker run -it --runtime=nvidia --name detectron-helmet \
                -v /helmet-project-realpath:/detectron/project \
                gouchicao/detectron:latest

修复BBOX_XFORM_CLIP错误

nano /detectron/detectron/utils/env.py 
yaml_load = lambda x: yaml.load(x, Loader=yaml.Loader)

工程设置 配置数据集 nano /detectron/detectron/datasets/dataset_catalog.

Jupyter Notebook实践

本地安装

云端环境

Binder

Google Colab

多用户版本

部署

使用Darknet在自定义数据集上训练YOLOv3

编译darknet

git clone https://github.com/pjreddie/darknet
cd darknet/
make

创建工程 工程目录结构 ├── darknet53.conv.74 基于imagenet的预训练模型 └── open-close 工程目录 ├── backup 存储模型训练时权重值 ├── cfg 配置目录 │ ├── train.txt 存储用于训练的图像路径 │ ├── valid.txt 存储用于验证的图像路径 │ ├── voc.data 配置文件 │ ├── voc.names 标签名 │ └── yolov3.cfg YOLOv3神经网络文件 ├── data │ └── labels 预测时用于显示标签名字 │ ├── 100_0.png │ ├── 100_1.png │ ├── ...... │ └── make_labels.py ├── images 图像样本集 │ ├── IMG_9255.JPG │ ├── IMG_9263.JPG │ ├── IMG_9266.JPG │ └── IMG_9280.JPG ├── labels PASCAL VOC格式的标注 │ ├── IMG_9255.xml │ ├── IMG_9263.xml │ ├── IMG_9266.xml │ └── IMG_9280.

Linux系统网络配置

Ubuntu

修改IP

$ sudo nano /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      addresses:
      - 172.16.33.1/24
      gateway4: 172.16.33.254
      nameservers: {}
  version: 2

应用配置

$ sudo netplan apply
# 推荐使用 debug 参数
$ sudo netplan --debug apply

或者

sudo netplan generate

验证

ip a | grep eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet 172.16.33.1/24 brd 172.16.33.255 scope global eno1

参考资料 How to setup a static IP on Ubuntu Server 18.04 How to configure Network Settings in Ubuntu 18.

Dockerfile JDK-MCR(MATLAB Compiler Runtime)

JDK-MCR(MATLAB Compiler Runtime)

FROM openjdk:latest
LABEL maintainer="wang-junjian@qq.com"

MAINTAINER Wang Junjian

RUN apt-get update && apt-get install -y curl wget unzip xorg

#Install MATLAB runtime
RUN mkdir /mcr-install && cd /mcr-install && \
    wget -nv http://ssd.mathworks.com/supportfiles/downloads/R2018b/deployment_files/R2018b/installers/glnxa64/MCR_R2018b_glnxa64_installer.zip && \
    unzip MCR_R2018b_glnxa64_installer.zip && \
    ./install -mode silent -agreeToLicense yes && \
    rm -Rf /mcr-install

ENV LD_LIBRARY_PATH /usr/local/MATLAB/MATLAB_Runtime/v95/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v95/extern/bin/glnxa64

CMD /bin/sh

搭建 Private Docker Registry

Registry

配置hosts

sudo nano /etc/hosts
10.10.10.10    HOSTNAME

运行registry

docker pull registry:2

sudo docker run -d \
    -p 5000:5000 \
    -v /home/ailab/docker-registry:/var/lib/registry \
    --restart=always \
    --name docker-registry \
    registry:2

修改Docker配置

sudo nano /etc/docker/daemon.json
{
    "live-restore": true,
    "group": "dockerroot",
    "insecure-registries": ["HOSTNAME:5000"]
}

重启Docker Engine

sudo systemctl restart docker

推送镜像

sudo docker tag hello-world:latest HOSTNAME:5000/hello-world:latest
sudo docker push HOSTNAME:5000/hello-world:latest

Registry UI

开启SSH服务

Ubuntu

  • 安装、卸载SSH服务
sudo apt-get install openssh-server
sudo apt-get remove openssh-server
  • 启动、停止、重启SSH服务
sudo service ssh start
sudo service ssh stop
sudo service ssh restart
  • 查询SSH服务状态
service ssh status
  • 配置文件(更改配置需要重启SSH服务)
sudo vi /etc/ssh/sshd_config
  • 连接SSH服务
ssh username@ip -p 22
  • 设置、移除SSH服务开机自启动
sudo update-rc.d ssh defaults
sudo update-rc.d ssh remove
  • 查看SSH服务设置的自启动
ls /etc/rc*
......
......
ls -l /etc/rc2.d/S02ssh
    lrwxrwxrwx 1 root root 13 12月 25 16:33 /etc/rc2.d/S02ssh -> ../init.d/ssh

参考资料