TGomsun2

[모두의ML] Lab 01(2/2) 실습

>>> hello = tf.constant("Hello, TensorFlow!")
>>> sess = tf.Session()
2018-04-14 00:10:36.813201: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> node1 = tf.constant(3.0, tf.float32)
>>> node2 = tf.constant(4.0)
>>> node3 = tf.add(node1, node2)
>>> node1
<tf.Tensor 'Const_1:0' shape=() dtype=float32>
>>> print('node1:', node1, 'node2:', node2)
node1: Tensor("Const_1:0", shape=(), dtype=float32) node2: Tensor("Const_2:0", shape=(), dtype=float32)
>>> print('node3:', node3)
node3: Tensor("Add:0", shape=(), dtype=float32)
>>> print(sess.run([node1, node2])
... )
[3.0, 4.0]
>>> print(sess.run(node3))
7.0
>>> print(sess.run(node1 + node2))
7.0
>>> print(sess.run([node1 + node2])
... )
[7.0]
>>> print(sess.run([node3])
... )
[7.0]
>>> print(node1)
Tensor("Const_1:0", shape=(), dtype=float32)
>>> helllo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'helllo' is not defined
>>> hello
<tf.Tensor 'Const:0' shape=() dtype=string>
>>> a = tf.placeholder(tf.float32)
>>> b = tf.placeholder(tf.float32)
>>> adder_node = a + b
>>> a
<tf.Tensor 'Placeholder:0' shape=<unknown> dtype=float32>
>>> b
<tf.Tensor 'Placeholder_1:0' shape=<unknown> dtype=float32>
>>> adder_node
<tf.Tensor 'add_2:0' shape=<unknown> dtype=float32>
>>> print(sess.run(adder_node, feed_dict={a: 3, b: 4.5}))
7.5
>>> print(sess.run(adder_node, feed_dict={a: [1,3], b:[2,4]}))
[3. 7.]
>>> feed_dict
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'feed_dict' is not defined
>>>

python에서는 n개의 변수가 있을 때, 변수 이름(keyword)를 통해 값을 할당하는 방식이 있다는 것을 확인.

그 꼴은

def run(self, fetches, feed_dict=None, options=None, run_metadata=None):\n
print(sess.run(adder_node, {a:3, b:5.5}))

이와 같은 코드도 동일하게 동작한다.

python문법의 특이한 점은, 인스턴스를 Self 매개 변수로 받는데, 자기 자신의 상태를 변경한 후 되돌려 주는 Chanining 느낌이었는데, 찾아보니.. Chaining을 목적으로 만든 함수.
see – https://stackoverflow.com/a/36251160/1174572

[모두의ML] Lab 01(1/2) – TensorFlow 실행시, not compiled to use: AVX2 FMA 경고

Python 3.6.3 (v3.6.3:2c5fed86e0, Oct  3 2017, 00:32:08)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.7.0'
>>> hello = tf.constant("Hello, TensorFlow!")
>>> sess = tf.Session()
2018-04-14 00:10:36.813201: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>

TF로 Hello TensorFlow를 출력했을 때,

I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

와 같은 메시지 확인을 해보니,
see – https://stackoverflow.com/a/47227886/1174572

내용인즉,

  • AVX: Advanced Vector Extensions
  • FMA: Fused Multiply–Add

벡터(행렬)과 실수연산에 GPU는 사용하지 못하고, CPU에 의존한 연산 수행.

노트북에는 Intel Iris 1536이 설치되어 있어서 확인
see – https://stackoverflow.com/a/40003475/1174572

At the moment no. Only Nvidia GPUs and (intel/amd) CPU versions are available.

… 그러함.

바람.
GPU는 없어도 되니, 모쪼록 이 자율 학습을 잘 이어나가기를 다짐하고, 기원합니다. (__)

TensorFlow 설치 및 오류

nstalling collected packages: numpy, pbr, funcsigs, six, mock, wheel, astor, backports.weakref, termcolor, gast, setuptools, protobuf, futures, grpcio, markdown, html5lib, bleach, werkzeug, tensorboard, absl-py, tensorflow
  Found existing installation: numpy 1.8.0rc1
    DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling numpy-1.8.0rc1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/m_/jkth_gd153s01vl0jygfzqxr0000gn/T/pip-HQYiiS-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'

해결 방법

 sudo -H pip install --ignore-installed numpy

2번째 오류

Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
    copytree(src, real_dst, symlinks=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', "[Errno 1] Operation not permitted: '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', "[Errno 1] Operation not permitted: '/tmp/pip-CKXUfm-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'")]

해결 2

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew upgrade python

결과

python3
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct  3 2017, 00:32:08)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'1.7.0'
>>>

Display Enumeration values on the DB Controls in Delphi

Display Enumeration values on the DB Controls in Delphi.

TRzDBComboBoxValues속성을 설정하는 것이 작성 코드도 적고, 편하다. TRzDBComboBox는 GetIt 패키지 매니져어서 Konopka(무료)를 설치하면 사용할 수 있습니다. https://stackoverflow.com/a/24981754/1174572 를 참고하여 작성했습니다.

Uses property of TRzDBCombox.Values is simple and easy. The component is part of Konopka package, and it can be download by GetIt package manager. I refer to the following link(https://stackoverflow.com/a/24981754/1174572).

Eumeration type

unit m.myenum;

uses
  System.Classes, System.SysUtils
  ;

type
  TMyEnum = (
    meOne,
    meTwo
  );
  TMyEnumHelper = record helper for TMyEnum
    class function ToStringArray: String; static;
    class function ToClientDataSet(const AOwner: TComponent): TClientDataSet; static;
    class function Create(const AValue: String): TMyEnum; static;
    function ToString: String;
    function ToInteger: Integer;
  end;

implementation

uses
  Spring.SystemUtils
  ;

class function TMyEnumHelper.ToStringArray: String;
var
  LItem: TMyEnum;
begin
  Result := [];
  for LItem := Low(TMyEnum) to High(TMyEnum) do
    Result := Result + [LItem.ToString];
end;

function TMyEnumHelper.ToString: String;
begin
  Result := TEnum.GetName<TMyEnum>(Self)
end;

function TMyEnumHelper.ToInteger: String;
begin
  Result := Integer(Self)
end;

class function TMyEnumHelper.Create(const AValue: String): TMyEnum;
begin
  Result := TEnum.Parse<TMyEnum>(AValue)
end;

class function TMyEnumHelper.ToClientDataSet(const AOwner: TComponent): TClientDataSet;
var
  LItem: TMyEnum;
begin
  Result := TClientDataSet.Create(AOwner);
  Result.FieldDefs.Add('ID', ftInteger);
  Result.FieldDefs.Add('MyEnum', ftString, 10);
  Result.CreateDataSet;
  Result.LogChanges := False;
  Result.Open;
  for LItem := Low(TMyEnum) to High(TMyEnum) do
  begin
    Result.Append;
    Result.FieldByName('ID').AsInteger := LItem.ToInteger;
    Result.FieldByName('MyEnum').AsString :=  LItem.ToString;
    Result.Post;
  end;
end;

Enitity

  TMyValue = class
  property 
    FEnums: TMyEnum;
    procedure SetEnumStrs(Value: String);
    function GetEnumStrs: String;
  public
    {Fields...}
    property Enums: TMyEnum read FEnums write FEnums;
    property AsEnumStrs: String read GetEnumStrs write SetEnumStrs;
    {More fields...}
  end;

implementation

function TMyValue.GetEnumStrs: String
begin
  Result := FEnums.ToString;
end;

procedure TMyValue.SetEnumStrs(Value: String);
begin
  FEnums := TMyEnum.Create(Value);
end;

uses TRzDBCombobox

type
  TvMyValueDlg = class(TForm)
    DataSrc: TDataSource;
    DataSet: TSimpleDataSet;
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

implementation

uses
  m.myenum
  ;

procedure TvMyValueDlg.FormCreate(Sender: TObject)
begin
  DBCombobox.Values.AddStrings(TMyEnum.ToStringArray);
end;

uses TDBLookupCombobox

type
  TvMyValueDlg = class(TForm)
    DataSrc: TDataSource;
    DataSet: TSimpleDataSet;
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

implementation

uses
  m.myenum
  ;

procedure TvMyValueDlg.FormCreate(Sender: TObject)
begin
  DataSrcLookUp := TDataSource.Create(Self);
  DataSrcLookUp.DataSet := TMyEnum.ToClientDataSet(Self);  
  DBLookupCombobox.DataSource := DataSrc;
  DBLookupComboBoxC2.DataField := 'FieldFromDataSrc';
  DBLookupComboBoxC2.ListSource := DataSrcLookUp;
  DBLookupComboBoxC2.ListField := 'MyEnum';
  DBLookupComboBoxC2.KeyField := 'ID'; // This field has to match to the field value which wants to looking up.
end;

문제해결: 사실-데이터-정보-지혜

앎은 ‘사실-데이터-정보-지식-지혜‘의 순서로 완성된다.

우선 사실(Fact)이 가장 기초이자 근본이 된다. 사실을 객관화시키면 데이터(Data)가 되고 이 데이터가 모이면 정보(Information)가 되며 다음 단계가 바로 지식(Knowledge)이다. 마지막으로 지식에 의미와 가치를 부여하면 보편적인 지식, 즉 지혜(Wisdom)가 된다. 사실에 근거한 데이터를 모아서 하나의 가치와 의미가 있는 정보와 지식으로 완성되는 것이다. 그 정보에 긴 안목 다양한 관점 그리고 업무 본질의 옷을 입히면 당신만의 지혜가 된다.

from: http://ppss.kr/archives/99693

  • 사실: 문제 발생
  • 정보(데이터의 조합): 재현경로, 소스분석 + 시나리오 완성, 재현을 위한 데이터 생성
  • 지식 문제 해결 방법, 방지 시나리오

지혜: 문제해결간 유사 또는 파생가능한 원리를 구현/해결하는 논리에서

  • 코드 작성에서 미연에 방지
  • 경험을 토대로 문제를 진단, 방치책을 논의

 

클래스의 상속과 Interface

인터페이스에 부모 세대와 동일 메소드 선언시,

해당 인터페이스의 구현체(인스턴스)는, 부모 메소드를 호출합니다.

program Project5;

{$APPTYPE CONSOLE}

{$R *.res}

uses
 System.SysUtils;

type
 TAClass = class(TInterfacedObject)
   procedure Foo;
 end;

 IFooBar = interface
 ['{016E8951-FF3A-486A-8C90-66A8C77708A7}']
   procedure Foo;
   procedure Bar;
 end;

 TBClass = class(TAClass, IFooBar)
   procedure Bar;
 end;

{ TAClass }

procedure TAClass.Foo;
begin
 WriteLn('Foo');
end;

{ TBClass }

procedure TBClass.Bar;
begin
 WriteLn('Bar');
end;

var
 LB: IFooBar;
begin
 LB := TBClass.Create;
 LB.Foo;
 LB.Bar;
 ReadLn;
end.

실행결과

Foo
Bar

Code Review

생애 첫 코드 리뷰, 모쪼록 팀+나를 성장에 +1을 희망하면서

그토록 원하던걸 해본 순간을 기록 합니다. 누군가에게 코멘트 한다는것이 참 어렵고 힘듭니다.  코멘트 후, 개발자들의 발표 자료에서, “팀간에 의사소통 방법,  노하우”, “사실 기록을 통한 의견 전달 방법”을 가 중요한지를 쪼끔은 이해하였습니다.

저도 생애 첫 코드리뷰를 작성하였습니다.

아마도 제가 작성한 코드역시 코멘트했던

  • 논리적 문제,
  • 네이밍 또는 띄어쓰기 규칙

등 많은 문제를 가지고 있을 것입니다.

모쪼록

  • 내 코드 말고 우리 코드
  • 나를 공격이 아닌, 우리 제품의 개선

으로 가는 과정임을 공감해 주셨으면 합니다.

물론 저도 리뷰간에 코멘트 해주시는 것들 달게 받고 우리의 개선으로 바라보도록 노력하겠습니다.

고생하셨고요, 잘 부탁드립니다. gs2 배상.

중간 관리자

조직에서 중간 간부만 되어도 초안을 자기가 쓰는 법이 없다. 그런데 모든 글은 처음 틀 잡는게 제일 어렵다. 제일 두뇌에 고통을 주는 일을 대리가 맡은 셈이다. 우리 회사도 대리, 과장이 쓴 어설픈 보고서를 내게 디밀고 딴청 부리는 부장들이 수두룩하다. 자기가 직접 쓴 글을 갖고 오는 경우는 희귀하다.

중간 간부만 되어도 직접 업무를 하지 않고 아래 사람에게 미룬다. 데이터도 직접 다루지 않고 글도 직접 쓰지 않는다. 지식의 심화도 이루어지지 않았는데 현장에서 멀어지니 원숙하고 창의적인 문제 해결은 기대하기 어렵다. 직접 팔을 걷어 부치고 뛰지 않고 부하로부터 보고만 받으니 아래 사람만 더 볶게 된다.

이렇게 되면 지식 노동자의 생산성은 순식간에 퇴화된다. 직접 고민을 하고 지식을 새롭게 자기가 만드는 수고를 잠시만 하지 않으면 처음 십년은 버틸지 몰라도 그 후에는 완전히 퇴화된다.

 

지식 노동자와 직장 민주화에서 발췌

assert Compier 지시자

{$ASSERTIONS ON/OFF} //long form
{$C +/-} //short form

Interface 형 변환

Class의 선언간 서로다른 Interface를 상속 하였고,

선언된 변수가 class의 부모 Interface Type 중 하나일 때,

해당 변수의 Instance를 Class Type으로 생성 하였다면,  상속한 다른 Interface Type으로 치환 할 수 있다.

program Project4;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

type
  IFoo = interface
    ['{1DE120CB-08C9-4534-AAF6-DA37BC049AD1}']
    procedure Foo;
  end;

  IBar = interface
    ['{1444D625-3690-43A2-A6DF-3223FED76203}']
    procedure Bar;
  end;

  TFooBar = class(TInterfacedObject, IFoo, IBar)
    procedure Foo;
    procedure Bar;
  end;

{ TFooBar }

procedure TFooBar.Foo;
begin
  WriteLn('Fooooooooooo')
end;

procedure TFooBar.Bar;
begin
  WriteLn('Bar')
end;

var
  LFoo: IFoo;
  LBar: IBar;
begin
  LFoo := TFooBar.Create;
  LFoo.Foo;
  if Supports(LFoo, IBar, LBar) then
    LBar.Bar;
  ReadLn;
end.

결과는

Fooooooooooo
Bar