diff --git a/AI/Pytorch/CodeLines.md b/AI/Pytorch/CodeLines.md index 2458136..7b448cf 100644 --- a/AI/Pytorch/CodeLines.md +++ b/AI/Pytorch/CodeLines.md @@ -1,4 +1,28 @@ -# General Pytorch code lines +# Pytorch + +## Run a docker container + +This container runs in background + +```bash +docker run -d -it --gpus all -name pytorch-container pytorch/pytorch:latest +``` + +## Connect to running container + +```bash +docker exec -it bash +docker exec -it bash -c "cat aap" +``` + +## Stop and start an execistion container + +```bash +docker stop +docker start +``` + +## Example code ```python # Load libraries @@ -11,5 +35,3 @@ from matplotlib.pyplot import plot, title, axis ```python device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") ``` - - diff --git a/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/1_gan.md b/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/1_gan.md index ab8f58c..b09bffe 100644 --- a/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/1_gan.md +++ b/Courses/GANs_Specialization/1_Build_Basic_GANs/Week_1:Intro_to_GANs/1_gan.md @@ -6,42 +6,45 @@ - The noise is larger to ensure that what's generated isn't actually the same dog each time - if you're only generating one class, one Y of a dog, then you probably don't need this conditioning on Y and instead it's just the probability over all the features X - ![two of the most popular generative model architectures](Images/Generative_Models.png) The two models in a GAN compete with each other and reach a point where realistic examples are produced by the generator. In the end, the Generator is not needed anymore, and only some random noise is used as input to generate some realistic image. - ## Goal of the generator and the discriminator + Generator learns to make **fake** that looks **real** and tries to fool the discriminator. Discriminator learns to **distinguish real** from **fake**, by looking to real and fake. - ## Competition between generator and the disciminator -In the beginning the generator is not very sophisticatied. + +In the beginning the generator is not very sophisticated. The generator is not to see the real. The discriminator start to learn the real. -Then the discrinator start to decide what is real and what is fake. +Then the discriminator start to decide what is real and what is fake. -When the generator starts to produce bathes of fake, the discriminator will know in what direction to go and improve to decide faje or real. +When the generator starts to produce bathes of fake, the discriminator will know in what direction to go and improve to decide fake or real. End: fakes look real. - ## Discriminator + - is a classifier + - not only images, but also eq text + - P(Y|X) => P(Class | Features) conditional probability distribution + - CLass is fake: so the discriminator will determinate a probalility how fake a class is. -![Disriminator probablility](Images/Dicriminator_probability.png) + ![Disriminator probablility](Images/Dicriminator_probability.png) - this probability is given back to generator. ## Generator + Goal: produce example of a certain class Noise vector: result is different outputs at every run @@ -55,6 +58,7 @@ If one class then for Generator P(X) if multiple classes then P(X|Y) ## BCE Cost Function + Binary Cross Entropy function, or BCE for short, is used for training GANs. Desinged for classification when there are two categories: real and fake. @@ -66,6 +70,7 @@ Negative sign: ensures that the cost is always>=0 ![BCE_LOss_Function](Images/BCE_Loss_function.png) Summary: + - BCE Cost function has two parts - Close to zero when the label and prediction are similar - Appraches infinity when the label and prediction are different @@ -85,12 +90,10 @@ Over time, it learns to discern real from fake better, but note that since the g With feedback from the discriminator on whether a fake image looks real or fake, the generator starts producing fake images that are more and more realistic (that tries to fool the discriminator). Images that look “fake” to the discriminator are discarded in favor of those that look “real” to the discriminator; since the discriminator is improving over time as it sees more reals and fakes, the generator needs to continually learn too. - So as you alternate their training, only **one model is trained at a time**, while the other one is held constant. So in training GANs in this alternating fashion, it's important to keep in mind that **both models should improve together and should be kept at similar skill levels** from the beginning of training. ![BCE_LOss_Function](Images/Traing_gan_similar_level.png) One common issue is having a **superior discriminator**, having this discriminator learn too quickly. And when it learns too quickly and it suddenly looks at a fake image and says, this is 100% fake. This 100% is not useful for **the generator at all because it doesn't know which way to grow and learn** - ![BCE_LOss_Function](Images/Pytorch_vs_Tensorflow.png) \ No newline at end of file diff --git a/Overig/Docker/commands.md b/Overig/Docker/commands.md index 6a83b95..6d472ce 100644 --- a/Overig/Docker/commands.md +++ b/Overig/Docker/commands.md @@ -1,46 +1,43 @@ # Docker -### connect to running container +This container runs in background + +```bash +docker run -d -it --gpus all -name pytorch-container pytorch/pytorch:latest +docker run -d -it --rm -v $(pwd):/src --gpus all -name pytorch-container pytorch/pytorch:latest +``` + +The latter removes the docker instance when stopped and alse has a volume + +## Connect to running container + ```bash docker exec -it bash +docker exec -it bash -c "cat aap" ``` -### start stopped container. See with docker ps -a + +## Stop and start an execistion container ```bash -docker start +docker stop +docker start ``` -### pytorch; standard container - -```bash -docker run -it --gpus all pytorch/pytorch:latest bash -docker run -d --gpus all pytorch/pytorch:latest # run as deamon -``` -docker logs -f - ### docker ipaddress or running container -docker inspect | grep '"IPAddress"' | head -n 1 +```bash +docker inspect | grep '"IPAddress"' | head -n 1 +``` -### run iterative python program directly - -docker run --rm -v $(pwd):/src --rm python:latest python /src/hello-world.py - -### run iterative python shell - -docker run --rm -it -v $(pwd):/src --rm python:latest python - -### run bash inside python container - -docker run --rm -it -v $(pwd):/src --rm python:latest /bin/bash - -### run a daemon with option -d +### Run Postgresql daemon and psql attach ```bash -docker run --rm --name my-postgres -e POSTGRES_PASSWORD=qw12aap -d postgres:latest -docker exec -it my-postgres psql -h localhost -U postgres -d postgres +docker run --name my-postgres -e POSTGRES_PASSWORD=qw12aap -d postgres:latest +docker exec -it my-postgres psql -h localhost -U postgres -d postgres ``` +inside: psql -U postgres -h my-postgres + ### docker files ```dockerfile @@ -51,20 +48,11 @@ CMD python3 /src/hello-world.py ### docker networks -Usage: docker network COMMAND - -Commands: -connect Connect a container to a network -create Create a network -disconnect Disconnect a container from a network -inspect Display detailed information on one or more networks -ls List networks -prune Remove all unused networks -rm Remove one or more networks - ```bash docker network create net_1 + docker run --rm -d --net net_1 --name my_py -v $(pwd):/src python:latest python3 /src/run.py + docker run --rm -it --net net_1 alpine:latest /bin/bash docker network create net_2 @@ -72,9 +60,7 @@ docker run --rm --name my-postgres --network net_2 -e POSTGRES_PASSWORD=qw12aap docker run -it --rm --name my_postgre2 --network net_2 postgres:latest /bin/bash ``` -inside: psql -U postgres -h my-postgres - -### Docker Compose +### Docker Compose; Container Network is created automatically ```docker-compose version: '3' diff --git a/Python/Algemeen/csv.md b/Python/Algemeen/csv.md index 3cfd38b..02b7196 100644 --- a/Python/Algemeen/csv.md +++ b/Python/Algemeen/csv.md @@ -1,9 +1,3 @@ ---- -title: csv -updated: 2022-04-25 10:47:01Z -created: 2022-04-25 10:45:25Z ---- - ```python import csv @@ -12,6 +6,7 @@ import csv with open('../datasets/mpg.csv') as csvfile: mpg = list(csv.DictReader(csvfile)) ``` + output gives dict with key the row number: [{'': '1', 'manufacturer': 'audi',