Category Archives: How to Fix

A method of collecting JS dynamic content by PHP

1、 Download and install phantomjs according to your own platform https://phantomjs.org/download.html

2、 Call a JS file to access the URL connection that needs to be collected

// Example using HTTP POST operation

"use strict";
var page = require('webpage').create(),
    system = require('system'),
    server = system.args[1],
    settings = {
    encoding: "utf8",
    headers: {
        "Content-Type": "text/html",
        "Cookie": "cookie",
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
    }
};

page.open(server, settings, function (status) {
    var content = page.evaluate(function() {
       return document.getElementById('uiContent').innerHTML;
    });
    console.log(content);
    phantom.exit();
});

3,

<?php
$url = $_REQUEST['url'];
$command = "phantomjs cread.js " . $url;
@exec($command,$content);
echo $content[0];

 

Bug: unable to download source code in idea, error cannot download sources sources not found for:XXX

Bug Description: idea can’t download the source code, click choose Resource & gt; [select source code package] to confirm and report an error.
Solution: enter the project in the command line interface pom.xml File folder, execute the following command:

mvn dependency:resolve -Dclassifier=sources

Note: do not directly execute the command in terminal in the lower left corner of idea, but in DOS interface.

VC + + compiler can not find the header file and rebuild failure

1. The header file cannot be found

If the associated path of the header file is not set properly, you need to add both the root directory and the subdirectory to the additional header file directory. For example, if there are two header files in the root directory and the subdirectories sub1 and sub2 that need to be referenced elsewhere, you should add the header file path to the additional package directory in this way:

$(SolutionDir)root

$(SolutionDir)root\sub1

$(SolutionDir)root\sub2

2. It is successful to compile a library alone, but rebuild prompts that the related projects fail to compile

In this case, the lazy relationship between project references is not set well. You should right-click on the solution, – gt; common properties – & gt; project dependencies, and set the lazy relationship between project references without omission. In this way, the rebuild will succeed on the top-level project. At the same time, the compilation of dynamic library and other similar problems can also be solved.

 

 

 

tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

After learning Chapter 5 of deep learning with Python, deeply learn the thermodynamic diagram for computer vision
5.4.3 visualization class activation
when running the code in tensorflow 2.0 environment

grads = K.gradients(african_elephant_output, last_conv_layer.output)[0]

replace with

grads = tf.keras.backend.gradients(african_elephant_output, last_conv_layer.output)[0]

The following errors still occur

tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

Solution

with tf.GradientTape() as gtape:
    grads = gtape.gradient(african_elephant_output, last_conv_layer.output)

Full code reference

reference resources:

https://stackoverflow.com/questions/58322147/how-to-generate-cnn-heatmaps-using-built-in-keras-in-tf2-0-tf-keras

ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256,

When testing the trained network, python finds the above problems and adds them after loading the network model.eval (), the problem is solved.

model = nn.DataParallel(model).cpu()
model.load_state_dict(torch.load(path, map_location=torch.device('cpu')), False)
model.eval()

There are three things to note about this code snippet

 nn.DataParallel(model)

If you add this function to the training network, you also need to add this function to the training network

model.load_state_dict(torch.load(path, map_location=torch.device('cpu')), False)

If the network framework is not saved when the network is saved and only parameters are available, the network can be loaded by the above method. If the GPU is used when the network is trained and the parameter map is added on the CPU when the network is used_ location= torch.device (‘cpu’)

model.eval()

The third is the problem of the topic. After loading the network, add the above function to solve the problem

Solution of modulenotfounderror in running pychar

Solution of modulenotfounderror in running pychar

You need to load the corresponding module file in pychar. The specific steps are as follows: left click in file, select settings, and select【 python:xxx 】Click [Python interperter] in the toolbar to open the page and select [add] in the toolbar, After the page appears, select [existing environment] to load python.exe File my python.exe The file is in the following location: C: users, administrator, appdata, local, programs, python, python38

Common problems

one python.exe There is no required module file in the file

At this time, you need to use pip to install the corresponding files. The installation steps are as follows:
1. Open CMD
2. Enter the CD in the folder (the following is my path) C:: (users / administrator / appdata / local / programs / Python / python38 / scripts)
3. Start to install the file PIP install flash (take installing flash as an example)
4. Check if the installation is complete, you can use pip to install flash List to determine whether the installed file is in the list

2. “PIP” is not an internal or external command

1. Confirm that “PIP” is not an internal or external command, nor a runnable program or batch file.

2. Solution 1: go to the folder where pip is located, and copy the path
my path is: C:: (users, administrator, appdata, local, programs, python, python38, scripts)

3. Switch the working directory to the path of PIP
CD

4. Execute PIP again, method 1, success!

5. Method 2: add pip to environment variables
right click my computer and select properties

6. Select: Advanced – environment variable

7. Open path to edit, and add the directory path of PIP at the end

8. After confirming the setting of environment variables, method 2 is successful!

Tensorflow: How to use expand_Dim() to add dimensions

In tensorflow, you can use to add one dimension to the dimension tf.expand_ Dims (input, dim, name = none) function. Of course, we often use it tf.reshape (input, shape = []) can also achieve the same effect, but sometimes in the process of building a graph, the placeholder is not fed with a specific value, and the following error will be included: type error: expected binary or Unicode string, got 1
in this case, we can consider using expand_ Dims to add one dimension. For example, in the case of my own code, when the image dimension is reduced to two dimensions, I need to restore it to four dimensions [batch, height, width, channels], and add one dimension before and after. If reshape is used, an error will be reported for the above reasons

one_img2 = tf.reshape(one_img, shape=[1, one_img.get_shape()[0].value, one_img.get_shape()[1].value, 1])

It can be realized by the following methods:

one_img = tf.expand_dims(one_img, 0)
one_img = tf.expand_dims(one_img, -1) #-1 denotes the last dimension

In the end, an official example is given

# 't' is a tensor of shape [2]
shape(expand_dims(t, 0)) ==> [1, 2]
shape(expand_dims(t, 1)) ==> [2, 1]
shape(expand_dims(t, -1)) ==> [2, 1]

# 't2' is a tensor of shape [2, 3, 5]
shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5]
shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5]
shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]

Args:
input: A Tensor.
dim: A Tensor. Must be one of the following types: int32, int64. 0-D (scalar). Specifies the dimension index at which to expand the shape of input.
name: A name for the operation (optional).
Returns:
A Tensor. Has the same type as input. Contains the same data as input, but its shape has an additional dimension of size 1 added.

Maven skip unit test- maven.test.skip And skipstests



-Dskiptests: do not execute test cases, but compile test case classes to generate corresponding class files under target / test classes.

– Dmaven.test.skip=true , do not execute test cases, and do not compile test case classes.

Do not execute the test case, but compile the test case class to generate the corresponding class file to target / test classes.

I. use maven.test.skip To skip not only the running of unit tests, but also the compiling of test code.

mvn package -Dmaven.test.skip=true  

It can also be in the pom.xml File modification

<plugin>  
    <groupId>org.apache.maven.plugin</groupId>  
    <artifactId>maven-compiler-plugin</artifactId>  
    <version>2.1</version>  
    <configuration>  
        <skip>true</skip>  
    </configuration>  
</plugin>  
<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-surefire-plugin</artifactId>  
    <version>2.5</version>  
    <configuration>  
        <skip>true</skip>  
    </configuration>  
</plugin> 

Second, use MVN package – dskipstests to skip the unit test, but will continue to compile; if there is no time to modify the unit test bug, or the unit test compilation error. Use the one above, not this one

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-surefire-plugin</artifactId>  
    <version>2.5</version>  
    <configuration>  
        <skipTests>true</skipTests>  
    </configuration>  
</plugin> 

=

Syntax error: unexpected EOF while parsing

SyntaxError: unexpected EOF while parsing

EOF is end of file, which mainly occurs when the syntax is incomplete

For example, the lack of parentheses at the end of list (map (lambda x: “char is =” + str (x), [i for I in range (1,10)] results in incomplete syntax

Correct: list (map (lambda x: “char is =” + str (x), [i for I in range (1,10)])