1. 입문과정(Mnist)

https://blog.nerdfactory.ai/2020/10/08/Tutorial-1-for-Deep-Learning-Model-Trainer-Development.html

 

너드팩토리

너드팩토리에서 운영하는 블로그 입니다.

blog.nerdfactory.ai

2. Criterion, Loss Function정리

[PyTorch] 자주쓰는 Loss Function (Cross-Entropy, MSE) 정리 - ZZEN’s Blog (nuguziii.github.io)

 

[PyTorch] 자주쓰는 Loss Function (Cross-Entropy, MSE) 정리

PyTorch에서 제가 개인적으로 자주쓰는 Loss Function (Cross Entropy, MSE) 들을 정리한 글입니다.

nuguziii.github.io

 

'PyTorch' 카테고리의 다른 글

설치된 파이토치 버전보기  (0) 2022.08.30
PyTorch 쿠다 환경 구성 (gpu 사용하기)  (0) 2022.08.28

 

[비동기처리 심화]

1. 비동기 처리를 할 때는 Future를 사용 ( Future(함수) , Future.delayed(duration, 함수)

2. async키워드를 사용하면 await를 사용할 수 있고 Future가 완료 된 후 다음 코드가 실행되도록 한다. 즉, 비동기방식을 동기화로 처리가능

 

 

[ Future ]  - 선입선출(FIFO)구조의 이벤트 중 하나

1. 다트에 의해서 future 객체가 내부적인 배열에 등록

2. Future 관련해서 실행되어야 하는 코드들이 이벤트 큐에 등록

3. 불완전한 future 객체가 반환

4. Synchronous 방식으로 실행되어야 할 코드 먼저 실행

5. 최종적으로 실제적인 data값이 future 객체로 전달

void main(){
  print('Before the Future');
  Future((){
    print('Running the Future');
  }).then((_){
    print('Future is complete');
  });
  print('After the Future');
}

 

출력결과(Synchronous부분 실행 후 Future가 실행되고 그 이후 then부분 출력 됨 )

Before the Future
After the Future
Running the Future
Future is complete

 

* Async 키워드 *

1. Async 키워드를 사용하는 순간 메서드를 통해서 나오는 결과들은 모두 future

2. Await 키워드를 만날때까지 Synchronous 방식으로 코드 처리

3. Await 키워드를 만나면 future가 완료될 때까지 대기

4. future가 완료 되자마자 그 다음 코드들을 실행

5. Async는 메서드가 비동기방식임을 선언하는 것이고 Future는 하나의 객체로 만들어질 때는 미완성이나 미래의 어느 시점에 온전한 데이터가 되거나 문제가 발생시 에러를 반환하는 객체가 된다.

 

아래 예제는 Future객체를 사용해서 비동기적으로 프로그램을 작성했는데 제대로 된 출력이 되지 않음

String createOrderMessage() {
  var order = fetchUserOrder();
  return 'Your order is: $order';
}

Future<String> fetchUserOrder() =>
    // Imagine that this function is
// more complex and slow.
Future.delayed(
  const Duration(seconds: 2),
      () => 'Large Latte',
);

void main() {
  print('Fetching user order...');
  print(createOrderMessage());
}

 

async와 await를 사용해서 제대로 처리해보기

Future<String> createOrderMessage() async {
  var order = await fetchUserOrder();
  return 'Your order is: $order';
}

Future<String> fetchUserOrder() =>
    // Imagine that this function is
// more complex and slow.
Future.delayed(
  const Duration(seconds: 2),
      () => 'Large Latte',
);

Future<void> main() async {
  print('Fetching user order...');
  print(await createOrderMessage());
}

 

정리

1. 비동기 처리를 할 때는 Future를 사용

2. async키워드를 사용하면 await를 사용할 수 있고 Future가 완료 된 후 다음 코드가 실행되도록 한다. 즉, 비동기방식을 동기화로 처리가능

 

 

참고(자바스크립트의 비동기처리-거의 동일)

1.

https://inpa.tistory.com/entry/JS-%F0%9F%93%9A-%EB%B9%84%EB%8F%99%EA%B8%B0%EC%B2%98%EB%A6%AC-async-await

 

[JS] 📚 비동기처리 (async / await) 개념 & 문법 💯 정리

비동기 처리 방식 자바스크립트는 싱글 스레드 프로그래밍언어기 때문에 비동기처리가 필수적이다. 비동기 처리는 그 결과가 언제 반환될지 알수 없기 때문에 동기식으로 처리하는 기법들이

inpa.tistory.com

https://velog.io/@khy226/%EB%8F%99%EA%B8%B0-%EB%B9%84%EB%8F%99%EA%B8%B0%EB%9E%80-Promise-asyncawait-%EA%B0%9C%EB%85%90

 

동기, 비동기란? (+Promise, async/await 개념)

1. 동기 vs. 비동기 우선 차이점 부터 설명하자면, 동기는 '직렬적'으로 작동하는 방식이고 비동기는 '병렬적'으로 작동하는 방식이다. 즉, 비동기란 특정 코드가 끝날때 까지 코드의 실행을 멈추

velog.io

 

for, for in, foreach, while문

List<type>.generate

void basicLoop(){
  List<String> rainbow = ['1','2','3','4','5','6'];

  for(int i=0; i<rainbow.length; i++){
    print(rainbow[i]);
  }

  for(String x in rainbow){
    print(x);
  }

  rainbow.forEach((name){
    print(name);
  });
}

void main(){
  basicLoop();
  return;
}

 

[로또번호 생성기 ver_1]

아래 프로그램은 list자료형의 특성상 random으로 값을 생성할 때 중복된 값을 허용함

import 'dart:math';

List<int> lottoNmber(){
  var random = Random();
  List<int> lottoList = [];
  var num;

  for(int i=0; i<6; i++){
    num = random.nextInt(45) + 1;
    lottoList.add(num);
  }

  print('당첨번호');
  print(lottoList);

  return lottoList;
}

List<int> myNumber(){
  var random = Random();
  List<int> myList = [];
  var num;

  for(int i=0; i<6; i++){
    num = random.nextInt(45) + 1;
    myList.add(num);
  }

  print('내 추첨번호');
  print(myList);

  return myList;
}

void checkNumber(lottoList, myList){

  int match = 0;

  for(int lotto in lottoList){
    for(int myNum in myList){
      if(lotto == myNum){
        match++;
        print('당첨번호: $lotto');
      }
      //print("로또번호 = $lotto");
      //print("내 추첨번호 = $myNum");
    }
  }
  print("$match개의 당첨번호가 있습니다.");
}

void main(){
  List<int>lottoFinal = lottoNmber();
  List<int>myFinal = myNumber();

  checkNumber(lottoFinal, myFinal);

  return;
}

 

[로또번호 생성기 ver_2]

set을 사용해서 중복된 값 제외하기

import 'dart:math';

Set<int> lottoNmber(){
  final random = Random();
  final Set<int> lottoSet = {};

  while(lottoSet.length != 6){
    lottoSet.add(random.nextInt(45)+1);
  }
  print('당첨번호');
  print(lottoSet.toList());

  return lottoSet;
}

Set<int> myNumber(){
  final random = Random();
  final Set<int> mySet = {};

  while(mySet.length != 6){
    mySet.add(random.nextInt(45)+1);
  }

  print('내 추첨번호');
  print(mySet.toList());
  return mySet;
}

void checkNumber(lottoSet, mySet){

  int match = 0;

  for(int lotto in lottoSet){
    for(int myNum in mySet){
      if(lotto == myNum){
        match++;
        print('당첨번호: $lotto');
      }
      //print("로또번호 = $lotto");
      //print("내 추첨번호 = $myNum");
    }
  }
  print("$match개의 당첨번호가 있습니다.");
}

void main(){
  Set<int>lottoFinal = lottoNmber();
  Set<int>myFinal = myNumber();

  checkNumber(lottoFinal, myFinal);

  return;
}

 

리스트 제너레이터

List<int>.generate(45, (i) => i+1);

예시

void main(){
  var text = List<int>.generate(45, (i) => i+1);
  print(text);
}

 

 

dart언어 cascade notation

class Person{
  String? name;
  int? age;

  void set(int x){
    age = x;
  }

  void show(){
    print(name);
    print(age);
  }
}

void main(){
  Person p1 = Person();
  p1.set(30);
  p1.name = "Lee";
  p1.show();

  Person p2 = Person();
  p2..set(20)..name = "Kim"..show();

  Person p3 = Person();
  p3..set(40)
    ..name="Park"
    ..show();
}

 

cascade 표기법을 활용해서 랜덤한 lotto 숫자 6개 뽑아내기

void main(){
  var test = (List<int>.generate(45, (i) => i+1)..shuffle()).sublist(0,6);
  print(test);
}

 

다시 로또프로그램 만들기

 

 

shutdown -s -f -t 14000

shutdown -r -f -t 14000

shutdown -a

https://mozi.tistory.com/402

https://mockaroo.com/

 

Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel

Mock your back-end API and start coding your UI today. It's hard to put together a meaningful UI prototype without making real requests to an API. By making real requests, you'll uncover problems with application flow, timing, and API design early, improvi

mockaroo.com

 

+ Recent posts