深度学习,服务器,计算机视觉,python文件操作,乱七八糟的代码

本文涵盖了Linux服务器后台运行程序、文件传输、系统监控、环境管理、深度学习框架(TensorFlow GPU、PyTorch CUDA)的测试,以及Python文件操作、文件夹管理、COCO数据集的处理和可视化等实用技巧。
摘要由CSDN通过智能技术生成

后台运行程序或shell

nohup bash train.sh > log 2>&1 &

服务器间文件传递

scp -r 当前服务器路径 目标用户@目标IP:目标服务器路径

查看文件夹大小

du -sh *

显示显卡状况

nvidia-smi

创建环境

conda create -n name python=3.x

删除环境

conda remove -n name --all

清华镜像安装pytorch

https://blog.csdn.net/qq_41375609/article/details/103574507

测试TensorFlow gpu

  • 2.X
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.Session()
  • 1.X
import tensorflow as tf
hello=tf.constant('hello,world')
sess=tf.Session()
print(sess.run(hello))

测试pytorch cuda

import torch
x = torch.Tensor([1.0])
xx = x.cuda()
print(xx)

用pip安装环境包时,结果安装到非当前环境

python3.8 -m pip install opencv-python
#3.8是为了区分环境,多个3.8环境就不加了

删除ps中多个进程

ps -ef|grep 关键词|grep -v grep|cut -c 9-15|xargs kill -9
   筛选出含有关键字的 不含有grep的 截取pid    杀死pid

jupyter notebook

选择conda中的环境,需要安装
conda install nb_conda

https://blog.csdn.net/qq_36017609/article/details/104271429

Windows中python循环创建文件夹

https://www.cnblogs.com/monsteryang/p/6574550.html

import os

def mkdir(path):
    # 引入模块
    # 去除首位空格
    path = path.strip()
    # 去除尾部 \ 符号
    path = path.rstrip("\\")

    # 判断路径是否存在
    # 存在     True
    # 不存在   False
    isExists = os.path.exists(path)

    # 判断结果
    if not isExists:
        # 如果不存在则创建目录
        # 创建目录操作函数
        os.makedirs(path)

        print(path + ' 创建成功')
        return True
    else:
        # 如果目录存在则不创建,并提示目录已存在
        print(path + ' 目录已存在')
        return False


# 定义要创建的目录
mkpath = "G:\\"
for i in range(1 , 20):
    mkdir(mkpath+str(i))
# 调用函数

批量命名文件夹

https://blog.csdn.net/ucs426/article/details/106522886/

import os, sys

myparth = r'D:\数据集'
files = os.listdir(myparth)  # 列举该目录下所有的文件夹
i = 1
for file in files:
    old_dir = os.path.join(myparth, file)  # 原来的文件路径
    # filename=os.path.split(old_dir)[0]
    new_dir = os.path.join(myparth, 'single_'+str(i))  # 现在的文件路径
    os.rename(old_dir, new_dir)  # 重命名
    i = i + 1
    print(i)

复制子文件下所有文件到另一个文件夹

import os
import shutil
path = '旧'
new_path = '新'

for root ,dirs,files in os.walk(path):
    for i in range(len(files)):
        if (files[i][-3:] == 'jpg') or (files[i][-3:] == 'png')or (files[i][-3:] == 'PNG') or (files[i][-3:] == 'JPG') or (files[i][-3:] == 'mp4'):
            file_path = root +'/'+files[i
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值