【Elasticsearch】-图片向量化存储

需要结合深度学习模型

1、pom依赖

注意结尾的webp-imageio 包,用于解决ImageIO.read读取部分图片返回为null的问题

<dependency><groupId>org.openpnp</groupId><artifactId>opencv</artifactId><version>4.7.0-0</version></dependency><dependency><groupId>com.microsoft.onnxruntime</groupId><artifactId>onnxruntime</artifactId><version>1.17.1</version></dependency><!-- 服务器端推理引擎 --><dependency><groupId>ai.djl</groupId><artifactId>api</artifactId><version>${djl.version}</version></dependency><dependency><groupId>ai.djl</groupId><artifactId>basicdataset</artifactId><version>${djl.version}</version></dependency><dependency><groupId>ai.djl</groupId><artifactId>model-zoo</artifactId><version>${djl.version}</version></dependency><!-- Pytorch --><dependency><groupId>ai.djl.pytorch</groupId><artifactId>pytorch-engine</artifactId><version>${djl.version}</version></dependency><dependency><groupId>ai.djl.pytorch</groupId><artifactId>pytorch-model-zoo</artifactId><version>${djl.version}</version></dependency><!-- ONNX --><dependency><groupId>ai.djl.onnxruntime</groupId><artifactId>onnxruntime-engine</artifactId><version>${djl.version}</version></dependency><!-- 解决ImageIO.read 读取为null --><dependency><groupId>org.sejda.imageio</groupId><artifactId>webp-imageio</artifactId><version>0.1.6</version></dependency>

2、加载模型

注意提前设置环境变量,pytorch依赖环境dll文件,如果不存在,则默认下载

System.setProperty("ENGINE_CACHE_DIR", modelPath);

import ai.djl.Device;
import ai.djl.modality.cv.Image;
import ai.djl.repository.zoo.Criteria;
import ai.djl.training.util.ProgressBar;
import ai.djl.translate.Translator;public Criteria<Image, T> criteria() {Translator<Image, T> translator = getTranslator(arguments);try {JarFileUtils.copyFileFromJar("/onnx/models/" + modelName, PathConstants.ONNX, null, false, true);} catch (IOException e) {throw new RuntimeException(e);}
//        String model_path = PathConstants.TEMP_DIR + PathConstants.ONNX + "/" + modelName;String modelPath = PathConstants.TEMP_DIR + File.separator+PathConstants.ONNX_NAME+ File.separator + modelName;log.info("路径修改前:{}",modelPath);modelPath= DjlHandlerUtil.getFixedModelPath(modelPath);log.info("路径修改后:{}",modelPath);Criteria<Image, T> criteria =Criteria.builder().setTypes(Image.class, getClassOfT()).optModelUrls(modelPath).optTranslator(translator).optDevice(Device.cpu()).optEngine(getEngine()) // Use PyTorch engine.optProgress(new ProgressBar()).build();return criteria;}protected Translator<Image, float[]> getTranslator(Map<String, Object> arguments) {BaseImageTranslator.BaseBuilder<?> builder=new BaseImageTranslator.BaseBuilder<BaseImageTranslator.BaseBuilder>() {@Overrideprotected BaseImageTranslator.BaseBuilder self() {return this;}};return new BaseImageTranslator<float[]>(builder) {@Overridepublic float[] processOutput(TranslatorContext translatorContext, NDList ndList) throws Exception {return ndList.get(0).toFloatArray();}};}

3、FaceFeatureTranslator

import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.transform.Normalize;
import ai.djl.modality.cv.transform.ToTensor;
import ai.djl.ndarray.NDArray;
import ai.djl.ndarray.NDList;
import ai.djl.translate.Batchifier;
import ai.djl.translate.Pipeline;
import ai.djl.translate.Translator;
import ai.djl.translate.TranslatorContext;/*** @author gc.x* @date 2022-04*/
public final class FaceFeatureTranslator implements Translator<Image, float[]> {public FaceFeatureTranslator() {}@Overridepublic NDList processInput(TranslatorContext ctx, Image input) {NDArray array = input.toNDArray(ctx.getNDManager(), Image.Flag.COLOR);Pipeline pipeline = new Pipeline();pipeline// .add(new Resize(160)).add(new ToTensor()).add(new Normalize(new float[]{127.5f / 255.0f, 127.5f / 255.0f, 127.5f / 255.0f},new float[]{128.0f / 255.0f, 128.0f / 255.0f, 128.0f / 255.0f}));return pipeline.transform(new NDList(array));}@Overridepublic float[] processOutput(TranslatorContext ctx, NDList list) {NDList result = new NDList();long numOutputs = list.singletonOrThrow().getShape().get(0);for (int i = 0; i < numOutputs; i++) {result.add(list.singletonOrThrow().get(i));}float[][] embeddings = result.stream().map(NDArray::toFloatArray).toArray(float[][]::new);float[] feature = new float[embeddings.length];for (int i = 0; i < embeddings.length; i++) {feature[i] = embeddings[i][0];}return feature;}@Overridepublic Batchifier getBatchifier() {return Batchifier.STACK;}
}

4、BaseImageTranslator


import ai.djl.Model;
import ai.djl.modality.cv.Image;
import ai.djl.modality.cv.transform.CenterCrop;
import ai.djl.modality.cv.transform.Normalize;
import ai.djl.modality.cv.transform.Resize;
import ai.djl.modality.cv.transform.ToTensor;
import ai.djl.modality.cv.util.NDImageUtils;
import ai.djl.ndarray.NDArray;
import ai.djl.ndarray.NDList;
import ai.djl.translate.*;
import ai.djl.util.Utils;import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;public abstract class BaseImageTranslator<T> implements Translator<Image, T> {private static final float[] MEAN = {0.485f, 0.456f, 0.406f};private static final float[] STD = {0.229f, 0.224f, 0.225f};private Image.Flag flag;private Pipeline pipeline;private Batchifier batchifier;/*** Constructs an ImageTranslator with the provided builder.** @param builder the data to build with*/public BaseImageTranslator(BaseBuilder<?> builder) {flag = builder.flag;pipeline = builder.pipeline;batchifier = builder.batchifier;}/** {@inheritDoc} */@Overridepublic Batchifier getBatchifier() {return batchifier;}/*** Processes the {@link Image} input and converts it to NDList.** @param ctx the toolkit that helps create the input NDArray* @param input the {@link Image} input* @return a {@link NDList}*/@Overridepublic NDList processInput(TranslatorContext ctx, Image input) {NDArray array = input.toNDArray(ctx.getNDManager(), flag);array = NDImageUtils.resize(array, 640, 640);array = array.transpose(2, 0, 1); // HWC -> CHW RGB -> BGR
//        array = array.expandDims(0);array = array.div(255f);return new NDList(array);
//        return pipeline.transform(new NDList(array));}protected static String getStringValue(Map<String, ?> arguments, String key, String def) {Object value = arguments.get(key);if (value == null) {return def;}return value.toString();}protected static int getIntValue(Map<String, ?> arguments, String key, int def) {Object value = arguments.get(key);if (value == null) {return def;}return (int) Double.parseDouble(value.toString());}protected static float getFloatValue(Map<String, ?> arguments, String key, float def) {Object value = arguments.get(key);if (value == null) {return def;}return (float) Double.parseDouble(value.toString());}protected static boolean getBooleanValue(Map<String, ?> arguments, String key, boolean def) {Object value = arguments.get(key);if (value == null) {return def;}return Boolean.parseBoolean(value.toString());}/*** A builder to extend for all classes extending the {@link BaseImageTranslator}.** @param <T> the concrete builder type*/@SuppressWarnings("rawtypes")public abstract static class BaseBuilder<T extends BaseBuilder> {protected int width = 224;protected int height = 224;protected Image.Flag flag = Image.Flag.COLOR;protected Pipeline pipeline;protected Batchifier batchifier = Batchifier.STACK;/*** Sets the optional {@link Image.Flag} (default is {@link* Image.Flag#COLOR}).** @param flag the color mode for the images* @return this builder*/public T optFlag(Image.Flag flag) {this.flag = flag;return self();}/*** Sets the {@link Pipeline} to use for pre-processing the image.** @param pipeline the pre-processing pipeline* @return this builder*/public T setPipeline(Pipeline pipeline) {this.pipeline = pipeline;return self();}/*** Adds the {@link Transform} to the {@link Pipeline} use for pre-processing the image.** @param transform the {@link Transform} to be added* @return this builder*/public T addTransform(Transform transform) {if (pipeline == null) {pipeline = new Pipeline();}pipeline.add(transform);return self();}/*** Sets the {@link Batchifier} for the {@link Translator}.** @param batchifier the {@link Batchifier} to be set* @return this builder*/public T optBatchifier(Batchifier batchifier) {this.batchifier = batchifier;return self();}protected abstract T self();protected void validate() {if (pipeline == null) {throw new IllegalArgumentException("pipeline is required.");}}protected void configPreProcess(Map<String, ?> arguments) {if (pipeline == null) {pipeline = new Pipeline();}width = getIntValue(arguments, "width", 224);height = getIntValue(arguments, "height", 224);if (arguments.containsKey("flag")) {flag = Image.Flag.valueOf(arguments.get("flag").toString());}if (getBooleanValue(arguments, "centerCrop", false)) {addTransform(new CenterCrop());}if (getBooleanValue(arguments, "resize", false)) {addTransform(new Resize(width, height));}if (getBooleanValue(arguments, "toTensor", true)) {addTransform(new ToTensor());}String normalize = getStringValue(arguments, "normalize", "false");if ("true".equals(normalize)) {addTransform(new Normalize(MEAN, STD));} else if (!"false".equals(normalize)) {String[] tokens = normalize.split("\\s*,\\s*");if (tokens.length != 6) {throw new IllegalArgumentException("Invalid normalize value: " + normalize);}float[] mean = {Float.parseFloat(tokens[0]),Float.parseFloat(tokens[1]),Float.parseFloat(tokens[2])};float[] std = {Float.parseFloat(tokens[3]),Float.parseFloat(tokens[4]),Float.parseFloat(tokens[5])};addTransform(new Normalize(mean, std));}String range = (String) arguments.get("range");if ("0,1".equals(range)) {addTransform(a -> a.div(255f));} else if ("-1,1".equals(range)) {addTransform(a -> a.div(128f).sub(1));}if (arguments.containsKey("batchifier")) {batchifier = Batchifier.fromString((String) arguments.get("batchifier"));}}protected void configPostProcess(Map<String, ?> arguments) {}}/** A Builder to construct a {@code ImageClassificationTranslator}. */@SuppressWarnings("rawtypes")public abstract static class ClassificationBuilder<T extends BaseBuilder>extends BaseBuilder<T> {protected SynsetLoader synsetLoader;/*** Sets the name of the synset file listing the potential classes for an image.** @param synsetArtifactName a file listing the potential classes for an image* @return the builder*/public T optSynsetArtifactName(String synsetArtifactName) {synsetLoader = new SynsetLoader(synsetArtifactName);return self();}/*** Sets the URL of the synset file.** @param synsetUrl the URL of the synset file* @return the builder*/public T optSynsetUrl(String synsetUrl) {try {this.synsetLoader = new SynsetLoader(new URL(synsetUrl));} catch (MalformedURLException e) {throw new IllegalArgumentException("Invalid synsetUrl: " + synsetUrl, e);}return self();}/*** Sets the potential classes for an image.** @param synset the potential classes for an image* @return the builder*/public T optSynset(List<String> synset) {synsetLoader = new SynsetLoader(synset);return self();}/** {@inheritDoc} */@Overrideprotected void validate() {super.validate();if (synsetLoader == null) {synsetLoader = new SynsetLoader("synset.txt");}}/** {@inheritDoc} */@Overrideprotected void configPostProcess(Map<String, ?> arguments) {String synset = (String) arguments.get("synset");if (synset != null) {optSynset(Arrays.asList(synset.split(",")));}String synsetUrl = (String) arguments.get("synsetUrl");if (synsetUrl != null) {optSynsetUrl(synsetUrl);}String synsetFileName = (String) arguments.get("synsetFileName");if (synsetFileName != null) {optSynsetArtifactName(synsetFileName);}}}protected static final class SynsetLoader {private String synsetFileName;private URL synsetUrl;private List<String> synset;public SynsetLoader(List<String> synset) {this.synset = synset;}public SynsetLoader(URL synsetUrl) {this.synsetUrl = synsetUrl;}public SynsetLoader(String synsetFileName) {this.synsetFileName = synsetFileName;}public List<String> load(Model model) throws IOException {if (synset != null) {return synset;} else if (synsetUrl != null) {try (InputStream is = synsetUrl.openStream()) {return Utils.readLines(is);}}return model.getArtifact(synsetFileName, Utils::readLines);}}
}

5、添加到ES

float[] feature;
// 构建文档Map<String, Object> dataMap = req.getDataMap();// 内置参数dataMap.put("_es_doc_type", "IMAGE");dataMap.put("vector", feature);IndexRequest<Map> request = IndexRequest.of(i -> i.index(req.getIndexLib()).id(req.getDocId()).document(dataMap));IndexResponse response = esClient.index(request);boolean flag = response.result() == Result.Created;log.info("添加文档id={},结果={}", req.getDocId(), flag);

6、pytorch环境依赖

cpu/linux-x86_64/native/lib/libc10.so.gz
cpu/linux-x86_64/native/lib/libtorch_cpu.so.gz
cpu/linux-x86_64/native/lib/libtorch.so.gz
cpu/linux-x86_64/native/lib/libgomp-52f2fd74.so.1.gz
cpu/osx-aarch64/native/lib/libtorch_cpu.dylib.gz
cpu/osx-aarch64/native/lib/libtorch.dylib.gz
cpu/osx-aarch64/native/lib/libc10.dylib.gz
cpu/osx-x86_64/native/lib/libtorch_cpu.dylib.gz
cpu/osx-x86_64/native/lib/libiomp5.dylib.gz
cpu/osx-x86_64/native/lib/libtorch.dylib.gz
cpu/osx-x86_64/native/lib/libc10.dylib.gz
cpu/win-x86_64/native/lib/torch.dll.gz
cpu/win-x86_64/native/lib/uv.dll.gz
cpu/win-x86_64/native/lib/torch_cpu.dll.gz
cpu/win-x86_64/native/lib/c10.dll.gz
cpu/win-x86_64/native/lib/fbgemm.dll.gz
cpu/win-x86_64/native/lib/libiomp5md.dll.gz
cpu/win-x86_64/native/lib/asmjit.dll.gz
cpu/win-x86_64/native/lib/libiompstubs5md.dll.gz
cpu-precxx11/linux-aarch64/native/lib/libc10.so.gz
cpu-precxx11/linux-aarch64/native/lib/libtorch_cpu.so.gz
cpu-precxx11/linux-aarch64/native/lib/libarm_compute-973e5a6b.so.gz
cpu-precxx11/linux-aarch64/native/lib/libopenblasp-r0-56e95da7.3.24.so.gz
cpu-precxx11/linux-aarch64/native/lib/libtorch.so.gz
cpu-precxx11/linux-aarch64/native/lib/libarm_compute_graph-6990f339.so.gz
cpu-precxx11/linux-aarch64/native/lib/libstdc%2B%2B.so.6.gz
cpu-precxx11/linux-aarch64/native/lib/libarm_compute_core-0793f69d.so.gz
cpu-precxx11/linux-aarch64/native/lib/libgfortran-b6d57c85.so.5.0.0.gz
cpu-precxx11/linux-aarch64/native/lib/libgomp-6e1a1d1b.so.1.0.0.gz
cpu-precxx11/linux-x86_64/native/lib/libgomp-a34b3233.so.1.gz
cpu-precxx11/linux-x86_64/native/lib/libc10.so.gz
cpu-precxx11/linux-x86_64/native/lib/libtorch_cpu.so.gz
cpu-precxx11/linux-x86_64/native/lib/libtorch.so.gz
cpu-precxx11/linux-x86_64/native/lib/libstdc%2B%2B.so.6.gz
cu121/linux-x86_64/native/lib/libc10_cuda.so.gz
cu121/linux-x86_64/native/lib/libcudnn.so.8.gz
cu121/linux-x86_64/native/lib/libnvfuser_codegen.so.gz
cu121/linux-x86_64/native/lib/libc10.so.gz
cu121/linux-x86_64/native/lib/libtorch_cpu.so.gz
cu121/linux-x86_64/native/lib/libcaffe2_nvrtc.so.gz
cu121/linux-x86_64/native/lib/libcudnn_adv_infer.so.8.gz
cu121/linux-x86_64/native/lib/libcudnn_cnn_train.so.8.gz
cu121/linux-x86_64/native/lib/libcudnn_ops_infer.so.8.gz
cu121/linux-x86_64/native/lib/libnvrtc-builtins-6c5639ce.so.12.1.gz
cu121/linux-x86_64/native/lib/libnvrtc-b51b459d.so.12.gz
cu121/linux-x86_64/native/lib/libtorch.so.gz
cu121/linux-x86_64/native/lib/libtorch_cuda_linalg.so.gz
cu121/linux-x86_64/native/lib/libcublas-37d11411.so.12.gz
cu121/linux-x86_64/native/lib/libtorch_cuda.so.gz
cu121/linux-x86_64/native/lib/libcudnn_adv_train.so.8.gz
cu121/linux-x86_64/native/lib/libcublasLt-f97bfc2c.so.12.gz
cu121/linux-x86_64/native/lib/libnvToolsExt-847d78f2.so.1.gz
cu121/linux-x86_64/native/lib/libcudnn_ops_train.so.8.gz
cu121/linux-x86_64/native/lib/libcudnn_cnn_infer.so.8.gz
cu121/linux-x86_64/native/lib/libgomp-52f2fd74.so.1.gz
cu121/linux-x86_64/native/lib/libcudart-9335f6a2.so.12.gz
cu121/win-x86_64/native/lib/zlibwapi.dll.gz
cu121/win-x86_64/native/lib/cudnn_ops_train64_8.dll.gz
cu121/win-x86_64/native/lib/torch.dll.gz
cu121/win-x86_64/native/lib/nvrtc-builtins64_121.dll.gz
cu121/win-x86_64/native/lib/cufftw64_11.dll.gz
cu121/win-x86_64/native/lib/cudnn_adv_infer64_8.dll.gz
cu121/win-x86_64/native/lib/nvrtc64_120_0.dll.gz
cu121/win-x86_64/native/lib/cusolverMg64_11.dll.gz
cu121/win-x86_64/native/lib/torch_cuda.dll.gz
cu121/win-x86_64/native/lib/cufft64_11.dll.gz
cu121/win-x86_64/native/lib/cublas64_12.dll.gz
cu121/win-x86_64/native/lib/cudnn64_8.dll.gz
cu121/win-x86_64/native/lib/uv.dll.gz
cu121/win-x86_64/native/lib/cudnn_cnn_train64_8.dll.gz
cu121/win-x86_64/native/lib/caffe2_nvrtc.dll.gz
cu121/win-x86_64/native/lib/torch_cpu.dll.gz
cu121/win-x86_64/native/lib/c10.dll.gz
cu121/win-x86_64/native/lib/cudnn_cnn_infer64_8.dll.gz
cu121/win-x86_64/native/lib/c10_cuda.dll.gz
cu121/win-x86_64/native/lib/cudart64_12.dll.gz
cu121/win-x86_64/native/lib/nvfuser_codegen.dll.gz
cu121/win-x86_64/native/lib/fbgemm.dll.gz
cu121/win-x86_64/native/lib/curand64_10.dll.gz
cu121/win-x86_64/native/lib/libiomp5md.dll.gz
cu121/win-x86_64/native/lib/cusolver64_11.dll.gz
cu121/win-x86_64/native/lib/cudnn_adv_train64_8.dll.gz
cu121/win-x86_64/native/lib/cublasLt64_12.dll.gz
cu121/win-x86_64/native/lib/nvToolsExt64_1.dll.gz
cu121/win-x86_64/native/lib/nvJitLink_120_0.dll.gz
cu121/win-x86_64/native/lib/cusparse64_12.dll.gz
cu121/win-x86_64/native/lib/asmjit.dll.gz
cu121/win-x86_64/native/lib/cudnn_ops_infer64_8.dll.gz
cu121/win-x86_64/native/lib/libiompstubs5md.dll.gz
cu121/win-x86_64/native/lib/cupti64_2023.1.1.dll.gz
cu121-precxx11/linux-x86_64/native/lib/libgomp-a34b3233.so.1.gz
cu121-precxx11/linux-x86_64/native/lib/libc10_cuda.so.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libnvfuser_codegen.so.gz
cu121-precxx11/linux-x86_64/native/lib/libc10.so.gz
cu121-precxx11/linux-x86_64/native/lib/libtorch_cpu.so.gz
cu121-precxx11/linux-x86_64/native/lib/libcaffe2_nvrtc.so.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_adv_infer.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_cnn_train.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_ops_infer.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libnvrtc-builtins-6c5639ce.so.12.1.gz
cu121-precxx11/linux-x86_64/native/lib/libnvrtc-b51b459d.so.12.gz
cu121-precxx11/linux-x86_64/native/lib/libtorch.so.gz
cu121-precxx11/linux-x86_64/native/lib/libtorch_cuda_linalg.so.gz
cu121-precxx11/linux-x86_64/native/lib/libcublas-37d11411.so.12.gz
cu121-precxx11/linux-x86_64/native/lib/libtorch_cuda.so.gz
cu121-precxx11/linux-x86_64/native/lib/libstdc%2B%2B.so.6.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_adv_train.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libcublasLt-f97bfc2c.so.12.gz
cu121-precxx11/linux-x86_64/native/lib/libnvToolsExt-847d78f2.so.1.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_ops_train.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libcudnn_cnn_infer.so.8.gz
cu121-precxx11/linux-x86_64/native/lib/libcudart-9335f6a2.so.12.gz
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/54373.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

docker存储

docker分层结构 如图所示&#xff0c;容器是由最上面可读可写的容器层&#xff0c;以及若干个只读镜像层组成&#xff0c;创建容器时&#xff0c;容器中的 数据都来自镜像层。这样的分层机构最大的特点是写时复制&#xff1a; 1、容器中新生成的数据会直接存放在容器层&#xf…

SAP 生产订单报工自动入库的几种处理方法

SAP 生产订单报工自动入库的几种处理方法 一、自动入库的功能与原理自动入库的核心机制包括:二、配置自动入库1. 控制关键字(Control Key)中的自动入库标志2. 生产订单类型设置三、自动入库的流程四、自动入库的优势五、适用场景六、业务场景七、系统配置点八、前台操作演示…

移动技术开发:登录注册界面

1 实验名称 登录注册界面 2 实验目的 掌握基本布局管理器的使用方法和基本控件的使用方法 3 实验源代码 布局文件代码&#xff1a; <?xml version"1.0" encoding"utf-8"?><LinearLayoutxmlns:android"http://schemas.android.com/apk/…

在Windows 7上安装Redis

1、下载Redis安装包‌&#xff1a; 首先&#xff0c;从Redis的官方网站或可信的第三方资源下载Redis的Windows版本安装包。确保下载与你的Windows 7系统兼容的版本。 2、解压安装包‌&#xff1a; 将下载的Redis安装包解压到你选择的目录&#xff0c;例如F:\Redis\redis-win…

关于文件操作

1. 为什么使⽤⽂件&#xff1f; 如果没有⽂件&#xff0c;我们写的程序的数据是存储在电脑的内存中&#xff0c;如果程序退出&#xff0c;内存回收&#xff0c;数据就丢失 了&#xff0c;等再次运⾏程序&#xff0c;是看不到上次程序的数据的&#xff0c;如果要将数据进⾏持久…

栈和队列的算法题目(C语言)

1. 括号匹配问题 20. 有效的括号 - 力扣&#xff08;LeetCode&#xff09; 利用栈后入先出的特性解题 1.判断字符串是否为空 为空返回 2.创建栈&#xff0c;遍历字符串 第一个字符是左括号的情况&#xff1a;入栈->继续遍历下一个字符 第一个字符是右括号的情况&#xf…

高等数学 3.3 泰勒公式

泰勒&#xff08;Taylor&#xff09;中值定理1 如果函数 f ( x ) f(x) f(x) 在 x 0 x_0 x0​ 处具有 n n n 阶导数&#xff0c;那么存在 x 0 x_0 x0​ 的一个邻域&#xff0c;对于该领域内的任一 x x x &#xff0c;有 f ( x ) f ( x 0 ) f ′ ( x 0 ) ( x − x 0 ) f…

CAD图1

文章目录 选择直线工具选择圆形选中圆形 选择直线工具 画一条十字中心线 选择圆形 以十字中心为起点画一个半径为 53 的圆形 选中圆形 选中圆形&#xff0c;捕捉右侧圆形焦点

Android AlertDialog圆角背景不生效的问题

一行解决: window?.setBackgroundDrawableResource(android.R.color.transparent) 原文件: /*** Created by Xinghai.Zhao* 自定义选择弹框*/ SuppressLint("InflateParams", "MissingInflatedId") class CustomDialog(context: Context?) : AlertDia…

【算法专题】穷举vs暴搜vs深搜vs回溯vs剪枝

二叉树剪枝 LCR 047. 二叉树剪枝 - 力扣&#xff08;LeetCode&#xff09; 本题要求我们将全部为0的二叉树去掉&#xff0c;也就是剪枝&#xff0c;当我们举一个具体的例子进行模拟时&#xff0c;会发现&#xff0c;只关注于对其中一个子树的根节点进行剪枝&#xff0c;由于我…

4款AI生成PPT工具推荐,提升工作效率

在如今的工作环境中&#xff0c;PPT制作是许多技术人员不可避免的任务&#xff0c;尤其是在汇报、展示技术方案、以及项目进展时。随着AI技术的快速发展&#xff0c;使用AI生成PPT成为了提高效率的一种新趋势。本文将介绍几款适合程序员、技术人员的AI生成PPT工具&#xff0c;帮…

Agent:原理与快速构建 | 人工智能 | Langchain | Python ——学习笔记

视频链接&#xff1a;https://www.bilibili.com/video/BV1Hz421b7ag/?spm_id_from333.788&vd_source90787f5794c8e73cf358973d1de2e47f # # 将.env的信息放到环境变量 # from dotenv import load_dotenv # load_dotenv() 第一节课程&#xff1a;使用openai调用智谱轻言问…

【Kubernetes】常见面试题汇总(十)

目录 29.简述 Kubernetes 自动扩容机制&#xff1f; 30.简述 Kubernetes Service 类型&#xff1f; 31.简述 Kubernetes Service 分发后端的策略&#xff1f; 32.简述 Kubernetes Headless Service &#xff1f; 29.简述 Kubernetes 自动扩容机制&#xff1f; &#xff08;…

强化学习——马尔可夫决策过程(MDP)【附 python 代码】

一、马尔可夫过程 过程介绍随机过程在某时刻 t 的状态 S t S_t St​ 通常取决于 t 时刻之前的状态。状态 S t 1 S_{t1} St1​ 的概率表示为&#xff1a; P ( S t 1 ∣ S 1 , . . . , S t ) P(S_{t1}|S_1,...,S_t) P(St1​∣S1​,...,St​)马尔可夫过程某时刻 t 的状态只取…

C++面试模拟01

第一部分&#xff1a;基础知识 问&#xff1a;解释 const 关键字的作用&#xff0c;以及在什么场景下你会使用 const&#xff1f; 问&#xff1a;在 C 中&#xff0c;new 和 malloc 的区别是什么&#xff1f; 问&#xff1a;请解释什么是“深拷贝”和“浅拷贝”&#xff1f;在…

IMS 呼叫流程(详细)

目录 业务模型 典型组网如图1所示 信令流程 具体的语音流程如图2所示 主叫信令面流程 01:UE_A->P-CSCF/ATCF 02:P-CSCF/ATCF_A->PCRF_A 03:PCRF_A->PCSCF/ATCF_A 04:P-CSCF/ATCF_A 处理(把S-CSCF加到Route) 05:S-CSCF_A->MMTel AS/SCC AS_A 06:MM…

JAVA-集合相关

HashMap如何解决哈希冲突的&#xff1f; 计算hash值&#xff0c;基于hashCode计算冲突之后&#xff0c;先是使用链式寻址法当链表长度大于8&#xff0c;且hash表的容量大于60的时候&#xff0c;再添加元素则转化成红黑树 为什么计算hash值是&#xff0c;是将hash地址的值右移1…

JavaSE:13、常用工具类

学习 资源1 学习资源 2 1、数学工具类 import com.test.*;import java.util.Random; import java.util.RandomAccess;public class Main {public static void main(String [] argv) throws Exception {System.out.println(Math.pow(5,3));//125.0System.out.println(Math.a…

大数据Flink(一百一十八):Flink SQL水印操作(Watermark)

文章目录 Flink SQL水印操作&#xff08;Watermark&#xff09; 一、为什么要有WaterMark 二、​​​​​​​​​​​​​​Watermark解决的问题 三、​​​​​​​​​​​​​​代码演示 Flink SQL水印操作&#xff08;Watermark&#xff09; 一、​​​​​​​为什么…

43.常用C++编译器推荐——《跟老吕学C++》

43.常用C编译器推荐——《跟老吕学C》 常用C编译器推荐一、C编译器介绍1. GCC (GNU Compiler Collection)2. Clang2.1 Clang的特点2.2 Clang的应用场景2.3 Clang与GCC的比较 3. Microsoft Visual C (MSVC)MSVC的特点MSVC的使用场景MSVC与其他编译器的比较 4. Intel C Compiler4…