-
1.环境配置
1.安装anaconda,利用anaconda激活虚拟环境
#在shell中输入如下命令来新建环境
conda create -n tensor_flow_25 python=3.8#这里指定python的版本为3.8 (>=3.6)
#查看虚拟环境的列表
conda list
#激活虚拟环境
conda activate tensor_flow_25
2.在虚拟环境内部输入如下代码配置环境
conda install tensorflow-gpu=2.5.0
等待安装完成,输入如下代码进行测试,通过
#进入python
python
#导入包
import tensorflow
#查看版本
tensorflow.__version__
2.量化权重并且读取中间结果
import logging
import re
from tensorflow.python.keras.applications.vgg16 import decode_predictions
logging.getLogger("tensorflow").setLevel(logging.DEBUG)
from tensorflow.lite.python import schema_py_generated as schema_fb
import matplotlib.pyplot as plt
from tensorflow.keras import models
import tensorflow as tf
import numpy as np
assert float(tf.__version__[:3]) >= 2.3
from tensorflow import keras
from tensorflow.python import pywrap_tensorflow
import pathlib
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input
import random
import flatbuffers
# 加载我的数据集
data_path = pathlib.Path('E:\\represent')
all_image_paths = list(data_path.glob('*/*'))
all_image_paths = [str(path) for path in all_image_paths] # 所有图片路径的列表
#random.shuffle(all_image_paths) # 打散
image_count = len(all_image_paths)
#print(image_count)
#print(all_image_paths[:5])
label_names = sorted(item.name for item in data_path.glob('*/') if item.is_dir())
#print(label_names[:5])
label_to_index = dict((name, index) for index, name in enumerate(label_names))
#print(label_